diff --git a/layout_paragraphs.module b/layout_paragraphs.module index c466206649d78ef41127f7d9367eccfe76cedc5e..f9df2c0d78d3f7b4f1d863edc4553a0dfba33f2c 100644 --- a/layout_paragraphs.module +++ b/layout_paragraphs.module @@ -124,6 +124,8 @@ function layout_paragraphs_preprocess_radios(&$variables) { /** * Implements hook_preprocess_layout_paragraphs_builder_controls(). + * + * @todo Consider adding an alter/info hook for altering this output. */ function layout_paragraphs_preprocess_layout_paragraphs_builder_controls(&$variables) { /** @var \Drupal\layout_paragraphs\LayoutParagraphsLayout $layout */ @@ -146,6 +148,7 @@ function layout_paragraphs_preprocess_layout_paragraphs_builder_controls(&$varia ], 'aria-describedy' => $id . '--tip', ], + '#weight' => 10, ], 'nav_tooltip' => [ '#type' => 'html_tag', @@ -157,6 +160,7 @@ function layout_paragraphs_preprocess_layout_paragraphs_builder_controls(&$varia 'id' => $id . '--tip', ], '#value' => t('Drag or click and use arrow keys to move. <br />Press Return or Tab when finished.'), + '#weight' => 20, ], 'label' => [ '#type' => 'html_tag', @@ -165,6 +169,7 @@ function layout_paragraphs_preprocess_layout_paragraphs_builder_controls(&$varia 'class' => ['lpb-controls-label'], ], '#value' => $entity->getParagraphType()->label, + '#weight' => 30, ], 'move_up' => [ '#type' => 'link', @@ -173,6 +178,7 @@ function layout_paragraphs_preprocess_layout_paragraphs_builder_controls(&$varia '#attributes' => [ 'class' => ['lpb-up'], ], + '#weight' => 40, ], 'move_down' => [ '#type' => 'link', @@ -181,6 +187,7 @@ function layout_paragraphs_preprocess_layout_paragraphs_builder_controls(&$varia '#attributes' => [ 'class' => ['lpb-down'], ], + '#weight' => 50, ], 'edit_link' => [ '#type' => 'link', @@ -198,6 +205,7 @@ function layout_paragraphs_preprocess_layout_paragraphs_builder_controls(&$varia 'data-dialog-options' => Json::encode(Dialog::dialogSettings($layout)), ], '#access' => $variables['edit_access'], + '#weight' => 60, ], 'delete_link' => [ '#type' => 'link', @@ -218,6 +226,7 @@ function layout_paragraphs_preprocess_layout_paragraphs_builder_controls(&$varia ]), ], '#access' => $variables['delete_access'], + '#weight' => 70, ], ]; if ($component->isLayout()) { diff --git a/src/Access/LayoutParagraphsBuilderAccess.php b/src/Access/LayoutParagraphsBuilderAccess.php index 39b4d827550db623fa1762524991c6d63cee16d2..b3fade4e74adc968afa1179675580b88028f5c2b 100644 --- a/src/Access/LayoutParagraphsBuilderAccess.php +++ b/src/Access/LayoutParagraphsBuilderAccess.php @@ -40,7 +40,7 @@ class LayoutParagraphsBuilderAccess implements AccessInterface { * @param \Drupal\layout_paragraphs\LayoutParagraphsLayout $layout_paragraphs_layout * The layout paragraphs layout object. * @param string $operation - * The operation being peformed (i.e. 'create' or 'delete'). + * The operation being performed (i.e. 'create' or 'delete'). * @param string $component_uuid * The specific component being acted on. * @param \Drupal\paragraphs\ParagraphsTypeInterface $paragraph_type diff --git a/src/Controller/ChooseComponentController.php b/src/Controller/ChooseComponentController.php index b5d6a46e2654707234ae5f82e9070e6a92fe461a..fc3136f6c41e215ecdb37c2b096481b3dfaaa70b 100644 --- a/src/Controller/ChooseComponentController.php +++ b/src/Controller/ChooseComponentController.php @@ -156,6 +156,7 @@ class ChooseComponentController extends ControllerBase { * Returns an array of allowed component types. */ public function getAllowedComponentTypes(LayoutParagraphsLayout $layout, $parent_uuid = NULL, $region = NULL) { + // @todo Document and add tests for what is happening here. $component_types = $this->getComponentTypes($layout); $event = new LayoutParagraphsAllowedTypesEvent($component_types, $layout, $parent_uuid, $region); $this->eventDispatcher->dispatch(LayoutParagraphsAllowedTypesEvent::EVENT_NAME, $event); diff --git a/src/Element/LayoutParagraphsBuilder.php b/src/Element/LayoutParagraphsBuilder.php index 587471aedd248f5a165049dc068e58fd7868d02a..ceac43f890fd8301901814065385f6f36ff7f760 100644 --- a/src/Element/LayoutParagraphsBuilder.php +++ b/src/Element/LayoutParagraphsBuilder.php @@ -5,7 +5,6 @@ namespace Drupal\layout_paragraphs\Element; use Drupal\Core\Url; use Drupal\Core\Render\Markup; use Drupal\Core\Render\Renderer; -use Drupal\Component\Utility\Html; use Drupal\Component\Serialization\Json; use Drupal\paragraphs\ParagraphInterface; use Drupal\Core\Access\AccessResultAllowed; @@ -148,7 +147,7 @@ class LayoutParagraphsBuilder extends RenderElement implements ContainerFactoryP * Properties: * - #layout_paragraphs_layout: a LayoutParagraphsLayout instance. * - #uuid: if provided, the uuid of the single paragraph to render. - * - #sounce_langcode: if provided, the source entity language. + * - #source_langcode: if provided, the source entity language. */ public function getInfo() { return [ @@ -164,6 +163,8 @@ class LayoutParagraphsBuilder extends RenderElement implements ContainerFactoryP /** * Pre-render callback: Renders the UI. + * + * @todo Better inline comments for all functionality in this method. */ public function preRender($element) { $this->layoutParagraphsLayout = $this->tempstore->get($element['#layout_paragraphs_layout']); diff --git a/src/Plugin/paragraphs/Behavior/LayoutParagraphsBehavior.php b/src/Plugin/paragraphs/Behavior/LayoutParagraphsBehavior.php index 67924e906dbda2ac35c5dbe14463f83dd26ba0c2..e27115832e9e895d019ee2be98cb40ebeaf8e797 100644 --- a/src/Plugin/paragraphs/Behavior/LayoutParagraphsBehavior.php +++ b/src/Plugin/paragraphs/Behavior/LayoutParagraphsBehavior.php @@ -126,7 +126,7 @@ class LayoutParagraphsBehavior extends ParagraphsBehaviorBase { $layout_id = Html::escape($layout_id); $default_value = !empty($layout_id) ? $layout_id : key($available_layouts); // @todo - Throw an error if plugin instance cannot be loaded. - $plugin_instance = $this->layoutPluginManager->createInstance($default_value, $layout_settings); + $plugin_instance = $this->layoutPluginManager->createInstance($default_value, $layout_settings ?? []); $plugin_form = $this->getLayoutPluginForm($plugin_instance); $wrapper_id = Html::getId(implode('-', array_merge($form['#parents'], ['layout-options']))); $form['layout'] = [ @@ -161,7 +161,7 @@ class LayoutParagraphsBehavior extends ParagraphsBehaviorBase { * {@inheritdoc} */ public function validateBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) { - $plugin_instance = $this->layoutPluginManager->createInstance($form_state->getValue('layout'), $form_state->getValue('config')); + $plugin_instance = $this->layoutPluginManager->createInstance($form_state->getValue('layout'), $form_state->getValue('config') ?? []); if ($plugin_form = $this->getLayoutPluginForm($plugin_instance)) { $plugin_form->validateConfigurationForm($form, $form_state); } @@ -172,7 +172,7 @@ class LayoutParagraphsBehavior extends ParagraphsBehaviorBase { */ public function submitBehaviorForm(ParagraphInterface $paragraph, array &$form, FormStateInterface $form_state) { $filtered_values = $this->filterBehaviorFormSubmitValues($paragraph, $form, $form_state); - $plugin_instance = $this->layoutPluginManager->createInstance($form_state->getValue('layout'), $form_state->getValue('config')); + $plugin_instance = $this->layoutPluginManager->createInstance($form_state->getValue('layout'), $form_state->getValue('config') ?? []); if ($plugin_form = $this->getLayoutPluginForm($plugin_instance)) { $subform_state = SubformState::createForSubform($form['config'], $form, $form_state); $plugin_form->submitConfigurationForm($form['config'], $subform_state);