Skip to content
Snippets Groups Projects
Commit eae8e542 authored by Eric Bremner's avatar Eric Bremner
Browse files

Coding standards

parent 1ee4d2e1
No related branches found
No related tags found
No related merge requests found
......@@ -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.
<?php
/**
* Implements template_preprocess_layout
* @file
* Functions for layout_builder_ids.
*/
/**
* Implements template_preprocess_layout.
*/
function layout_builder_ids_preprocess_layout(&$variables) {
......
......@@ -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',
];
}
}
......@@ -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',
];
}
}
......@@ -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;
}
......
<?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');
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment