diff --git a/README.txt b/README.txt index 6dee531f53a70846d4297d59bd0cd5a689dd4308..14331c0a31fe683f1845b8fb8a5ee30ea39fc6ed 100644 --- a/README.txt +++ b/README.txt @@ -9,7 +9,12 @@ CONTENTS OF THIS FILE INTRODUCTION ------------ -Layout Builder Ids allows site builders to enter and ID to be used with either a section or block in layout builder. A "style" is just a representation of one or more CSS classes that will be applied. This will then allow for things like anchor links and javascript to target very specific blocks and sections. +Layout Builder Ids allows site builders to enter and ID to +be used with either a section or block in layout builder. +A "style" is just a representation of one or more CSS classes +that will be applied. This will then allow for things like +anchor links and javascript to target very specific blocks +and sections. * For a full description of the module, visit the project page: https://www.drupal.org/project/layout_builder_ids/ @@ -36,4 +41,6 @@ INSTALLATION CONFIGURATION ------------- -When placing a block or section into a layout, this module will add an option for an ID, where ids follow the protocol of https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id. +When placing a block or section into a layout, this module will add an +option for an ID, where ids follow the protocol of +https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id. diff --git a/layout_builder_ids.module b/layout_builder_ids.module index 9d9354e1784e2cc3cc56eb625ad6d4cb0fdbed66..ffb305d9bf308862e55af1aecc36c2ca6bc6424c 100644 --- a/layout_builder_ids.module +++ b/layout_builder_ids.module @@ -1,7 +1,12 @@ <?php /** - * Implements template_preprocess_layout + * @file + * Functions for layout_builder_ids. + */ + +/** + * Implements template_preprocess_layout. */ function layout_builder_ids_preprocess_layout(&$variables) { diff --git a/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php b/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php index f235ce2c0a969836c2e962d0b2026c97044278b3..a9fcde75f390f4e846323925b54661985ba45205 100644 --- a/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php +++ b/src/EventSubscriber/LayoutBuilderIdsConfigureBlock.php @@ -4,14 +4,12 @@ namespace Drupal\layout_builder_ids\EventSubscriber; use Drupal\Core\Form\FormStateInterface; use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent; -use Drupal\core_event_dispatcher\Event\Form\FormBaseAlterEvent; -use Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent; use Drupal\hook_event_dispatcher\HookEventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\Component\Utility\Html; /** - * Class LayoutBuilderIdsConfigureBlock. + * Add block ids to layout builder sections. */ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface { @@ -27,7 +25,13 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface { $form = &$event->getForm(); // If we are on a configure section form, alter it. - if (in_array($form['#form_id'], ['layout_builder_add_block', 'layout_builder_update_block'], TRUE)) { + if ( + in_array( + $form['#form_id'], + ['layout_builder_add_block', 'layout_builder_update_block'], + TRUE + ) + ) { // Pull out the layout_builder_id from config. $layout_builder_id = &$event->getFormState()->getFormObject()->getCurrentComponent()->get('layout_builder_id'); @@ -42,14 +46,14 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface { ]; // Add our custom submit function. - array_unshift($form['#submit'], [$this, 'LayoutBuilderIdsSubmitForm']); + array_unshift($form['#submit'], [$this, 'layoutBuilderIdsSubmitForm']); } } /** * {@inheritdoc} */ - public function LayoutBuilderIdsSubmitForm(array &$form, FormStateInterface $form_state) { + public function layoutBuilderIdsSubmitForm(array &$form, FormStateInterface $form_state) { // Load in the layout_builder_id. $layout_builder_id = $form_state->getValue(['settings', 'layout_builder_id']); @@ -75,4 +79,5 @@ class LayoutBuilderIdsConfigureBlock implements EventSubscriberInterface { HookEventDispatcherInterface::FORM_ALTER => 'alterForm', ]; } + } diff --git a/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php b/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php index e2a07f0f6eed276bad68930702f3e77e2385c60e..7c2580c80b7bafadc500dd98e4491fe890998460 100644 --- a/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php +++ b/src/EventSubscriber/LayoutBuilderIdsConfigureSection.php @@ -4,15 +4,12 @@ namespace Drupal\layout_builder_ids\EventSubscriber; use Drupal\Core\Form\FormStateInterface; use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent; -use Drupal\core_event_dispatcher\Event\Form\FormBaseAlterEvent; -use Drupal\core_event_dispatcher\Event\Form\FormIdAlterEvent; use Drupal\hook_event_dispatcher\HookEventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\Component\Utility\Html; - /** - * Class LayoutBuilderIdsConfigureSection. + * Add section id to layout builder sections. */ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface { @@ -43,17 +40,23 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface { ]; // Add our custom submit handler. - array_unshift($form['#submit'], [$this, 'LayoutBuilderIdsSubmitForm']); + array_unshift($form['#submit'], [$this, 'layoutBuilderIdsSubmitForm']); } } /** * {@inheritdoc} */ - public function LayoutBuilderIdsSubmitForm(array &$form, FormStateInterface $form_state) { + public function layoutBuilderIdsSubmitForm(array &$form, FormStateInterface $form_state) { // Get the layout builder id from the form. - $layout_builder_id = $form_state->getValue(['layout_settings', 'layout_builder_id'], NULL); + $layout_builder_id = $form_state->getValue( + [ + 'layout_settings', + 'layout_builder_id', + ], + NULL + ); // If there is a layout builder id, store it. if ($layout_builder_id !== NULL) { @@ -74,9 +77,10 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface { } /** - * Get the layout object - * @param FormStateInterface $form_state - * @return mixed + * Get the layout object. + * + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state object. */ private function getLayout(FormStateInterface $form_state) { @@ -94,4 +98,5 @@ class LayoutBuilderIdsConfigureSection implements EventSubscriberInterface { HookEventDispatcherInterface::FORM_ALTER => 'alterForm', ]; } + } diff --git a/src/EventSubscriber/LayoutBuilderIdsRenderSubscriber.php b/src/EventSubscriber/LayoutBuilderIdsRenderSubscriber.php index 8e3edf8762cdfa291388b9c2d6645df999f72822..3188635ca01f8bc66ca4d8adc8f286b05c09d4e9 100644 --- a/src/EventSubscriber/LayoutBuilderIdsRenderSubscriber.php +++ b/src/EventSubscriber/LayoutBuilderIdsRenderSubscriber.php @@ -2,23 +2,27 @@ namespace Drupal\layout_builder_ids\EventSubscriber; -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\layout_builder\LayoutBuilderEvents; /** - * Class BlockComponentRenderArraySubscriber. + * Render the layout with block ids. */ class LayoutBuilderIdsRenderSubscriber implements EventSubscriberInterface { + /** * {@inheritdoc} */ public static function getSubscribedEvents() { + // Layout Builder also subscribes to this event to build the initial render // array. We use a higher weight so that we execute after it. - $events[LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY] = ['onBuildRender', 50]; + $events[LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY] = [ + 'onBuildRender', + 50, + ]; + return $events; } diff --git a/src/EventSubscriber/LayoutBuilderIdsRouteSubscriber.php b/src/EventSubscriber/LayoutBuilderIdsRouteSubscriber.php index 3441704f27752c9b590c48df8c08da68200e2f2f..30fe184be0c00050cd905fbe32ebbe7c953316a8 100644 --- a/src/EventSubscriber/LayoutBuilderIdsRouteSubscriber.php +++ b/src/EventSubscriber/LayoutBuilderIdsRouteSubscriber.php @@ -1,24 +1,24 @@ -<?php - -namespace Drupal\layout_builder_ids\EventSubscriber; - -use Drupal\Core\Routing\RouteSubscriberBase; -use Symfony\Component\Routing\RouteCollection; - -/** - * Class RouteSubscriber. - */ -class LayoutBuilderIdsRouteSubscriber extends RouteSubscriberBase { - - /** - * {@inheritdoc} - */ - protected function alterRoutes(RouteCollection $collection) { - - $configureSectionRoute = $collection->get('layout_builder.configure_section'); - if ($configureSectionRoute) { - $configureSectionRoute->setDefault('_form', '\Drupal\layout_builder_ids\Form\ConfigureSectionForm'); - } - } - -} +<?php + +namespace Drupal\layout_builder_ids\EventSubscriber; + +use Drupal\Core\Routing\RouteSubscriberBase; +use Symfony\Component\Routing\RouteCollection; + +/** + * Class RouteSubscriber. + */ +class LayoutBuilderIdsRouteSubscriber extends RouteSubscriberBase { + + /** + * {@inheritdoc} + */ + protected function alterRoutes(RouteCollection $collection) { + + $configureSectionRoute = $collection->get('layout_builder.configure_section'); + if ($configureSectionRoute) { + $configureSectionRoute->setDefault('_form', '\Drupal\layout_builder_ids\Form\ConfigureSectionForm'); + } + } + +}