-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
Reader
App on Route "/reader"
The `/reader` route now passes either the `identifier` or `orderId` parameters to the `Reader` React app. This was implemented to ensure the proper loading of external scripts that require a full page reload.
- Loading branch information
1 parent
6b170e7
commit fe5b354
Showing
5 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
web/modules/custom/dpl_react_apps/src/Plugin/Block/ReaderAppBlock.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace Drupal\dpl_react_apps\Plugin\Block; | ||
|
||
use Drupal\Core\Block\BlockBase; | ||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Provides a block for the Reader React app. | ||
* | ||
* @Block( | ||
* id = "reader_app_block", | ||
* admin_label = "Reader App" | ||
* ) | ||
*/ | ||
class ReaderAppBlock extends BlockBase implements ContainerFactoryPluginInterface { | ||
|
||
/** | ||
* A unique identifier for the Reader resource. | ||
* | ||
* @var string | ||
*/ | ||
protected string $identifier; | ||
|
||
/** | ||
* ReaderAppBlock constructor. | ||
* | ||
* @param array $configuration | ||
* A configuration array containing information about the plugin instance. | ||
* @param string $plugin_id | ||
* The plugin ID for the plugin instance. | ||
* @param array $plugin_definition | ||
* The plugin implementation definition. | ||
*/ | ||
public function __construct(array $configuration, string $plugin_id, array $plugin_definition) { | ||
parent::__construct($configuration, $plugin_id, $plugin_definition); | ||
|
||
// Assign the identifier from the configuration if available. | ||
if (isset($configuration['identifier'])) { | ||
$this->identifier = $configuration['identifier']; | ||
} | ||
else { | ||
// Default to an empty string if not provided. | ||
$this->identifier = 'Default'; | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | ||
return new static($configuration, $plugin_id, $plugin_definition); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @return mixed[] | ||
* Render array for the Reader app. | ||
*/ | ||
public function build(): array { | ||
$data = [ | ||
'identifier' => $this->identifier ?? NULL, | ||
'orderId' => $this->orderId ?? NULL, | ||
]; | ||
|
||
return [ | ||
'#theme' => 'dpl_react_app', | ||
'#name' => 'reader', | ||
'#data' => $data, | ||
]; | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
web/themes/custom/novel/templates/layout/page--reader.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{# | ||
/** | ||
* @file | ||
* Theme override to display a /reader page. | ||
* | ||
* This template is a variant of the page.html.twig template used for rendering | ||
* the user registration page. As we don't want the user accessing things outside | ||
* of the registration form, we have removed the header and footer regions for this | ||
* page. | ||
* | ||
* Available variables: | ||
* | ||
* General utility variables: | ||
* - base_path: The base URL path of the Drupal installation. Will usually be | ||
* "/" unless you have installed Drupal in a sub-directory. | ||
* - is_front: A flag indicating if the current page is the front page. | ||
* - logged_in: A flag indicating if the user is registered and signed in. | ||
* - is_admin: A flag indicating if the user has permission to access | ||
* administration pages. | ||
* | ||
* Site identity: | ||
* - front_page: The URL of the front page. Use this instead of base_path when | ||
* linking to the front page. This includes the language domain or prefix. | ||
* | ||
* Page content (in order of occurrence in the default page.html.twig): | ||
* - node: Fully loaded node, if there is an automatically-loaded node | ||
* associated with the page and the node ID is the second argument in the | ||
* page's path (e.g. node/12345 and node/12345/revisions, but not | ||
* comment/reply/12345). | ||
* | ||
* Regions: | ||
* - page.header: Items for the header region. | ||
* - page.primary_menu: Items for the primary menu region. | ||
* - page.secondary_menu: Items for the secondary menu region. | ||
* - page.highlighted: Items for the highlighted content region. | ||
* - page.help: Dynamic help text, mostly for admin pages. | ||
* - page.content: The main content of the current page. | ||
* - page.sidebar_first: Items for the first sidebar. | ||
* - page.sidebar_second: Items for the second sidebar. | ||
* - page.footer: Items for the footer region. | ||
* - page.breadcrumb: Items for the breadcrumb region. | ||
* | ||
* @see template_preprocess_page() | ||
* @see html.html.twig | ||
*/ | ||
#} | ||
|
||
<div> | ||
{{ drupal_block('system_messages_block') }} | ||
|
||
<main id="main-content" role="main"> | ||
{{ page.content }} | ||
</main> | ||
</div> |