diff --git a/config/install/layout_paragraphs.settings.yml b/config/install/layout_paragraphs.settings.yml index cb4544150078d8e86bc5f711f5a20d00897a989e..69cd4c2662369696ffbf53149cbff4a41f69c7d0 100644 --- a/config/install/layout_paragraphs.settings.yml +++ b/config/install/layout_paragraphs.settings.yml @@ -1 +1,2 @@ show_paragraph_labels: 0 +show_layout_labels: 0 diff --git a/config/schema/layout_paragraphs.schema.yml b/config/schema/layout_paragraphs.schema.yml index dda1966e56563c190ec67d9b4cdb66719c593eed..b5ac4b6342430e207523e4bb173d1bf89be25a19 100644 --- a/config/schema/layout_paragraphs.schema.yml +++ b/config/schema/layout_paragraphs.schema.yml @@ -1,8 +1,12 @@ -layou_paragraphs.settings: +layout_paragraphs.settings: type: config_object label: 'Layout Paragraphs general settings' mapping: show_paragraph_labels: type: integer label: 'Show Paragraph Labels' - description: 'This option allows to show the Paragraphs Type Label of each Item added in ERL widget Sections/Layouts' + description: 'This option allows to show the Paragraphs Type Label of each Item added in LP widget Sections/Layouts' + show_layout_labels: + type: integer + label: 'Show Layout Labels' + description: 'This option allows to show the Paragraphs Layout Label of each Item added in LP widget Sections/Layouts' diff --git a/css/layout-paragraphs-widget.css b/css/layout-paragraphs-widget.css index f7b373d1fa587593f19499dd6540769c967e8f8d..0f826938cb04941f550b7bf8aa6a1a51b0f27a70 100644 --- a/css/layout-paragraphs-widget.css +++ b/css/layout-paragraphs-widget.css @@ -98,8 +98,8 @@ fieldset.layout-paragraphs-field > legend { position: relative; border: 1px dashed #e5e5e3; transition: all .15s linear; - min-height: 30px; - padding: 30px; + min-height: 50px; + padding: 10px; } /* -- Warnings -- */ @@ -672,3 +672,29 @@ button.layout-paragraphs-add-content__toggle.active { border: lightgray dashed 1px; opacity: 0.7; } + +/* -- Paragraphs and Layout Labels. -- */ + +.paragraph-type-label { + position: absolute; + bottom: 0; + right: 0; + padding: 5px; + margin: 0; + border-top: 1px dashed #e5e5e3; + border-left: 1px dashed #e5e5e3; + font-style: italic; + font-weight: normal !important; + color: darkgray; +} + +.paragraph-layout-label { + position: absolute; + top: 0; + left: 50%; + padding: 0; + margin: auto; + font-style: italic; + font-weight: normal !important; + color: darkgray; +} diff --git a/layout_paragraphs.links.menu.yml b/layout_paragraphs.links.menu.yml index 159cd2beac4cd4871e540bddacae38fb01a5ae09..09092cc19a0b31d5560f381111a9ea608056f0b6 100644 --- a/layout_paragraphs.links.menu.yml +++ b/layout_paragraphs.links.menu.yml @@ -1,4 +1,4 @@ layout_paragraphs.settings: - title: 'Entity Reference Layout settings' + title: 'Layout Paragraphs settings' parent: system.admin_config_content route_name: layout_paragraphs.settings diff --git a/layout_paragraphs.routing.yml b/layout_paragraphs.routing.yml index abcaedc3c6d1fca557d9f3874de0aa6c4bdc6eb4..5ab58f6b7c3a77d8ecca7895b8c0ba0564e5a3cf 100644 --- a/layout_paragraphs.routing.yml +++ b/layout_paragraphs.routing.yml @@ -1,7 +1,7 @@ layout_paragraphs.settings: path: '/admin/config/content/layout_paragraphs' defaults: - _form: '\Drupal\layout_paragraphs\Form\EntityReferenceLayoutSettingsForm' - _title: 'Entity Reference Layout general settings' + _form: '\Drupal\layout_paragraphs\Form\LayoutParagraphsSettingsForm' + _title: 'Layout Paragraphs general settings' requirements: _permission: 'administer site configuration' diff --git a/src/Form/LayoutParagraphsSettingsForm.php b/src/Form/LayoutParagraphsSettingsForm.php index a15e65b8c57637602a2bd3a7fe98cce7700260d2..211d2bd6988bbe5bc95a4df6277fc141b49a14d9 100644 --- a/src/Form/LayoutParagraphsSettingsForm.php +++ b/src/Form/LayoutParagraphsSettingsForm.php @@ -66,16 +66,24 @@ class LayoutParagraphsSettingsForm extends ConfigFormBase { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { - $config = $this->configFactory()->getEditable('layout_paragraphs.settings'); - $erl_config_schema = $this->typedConfigManager->getDefinition('layout_paragraphs.settings') + ['mapping' => []]; - $erl_config_schema = $erl_config_schema['mapping']; + $lp_config = $this->configFactory()->getEditable('layout_paragraphs.settings'); + $lp_config_schema = $this->typedConfigManager->getDefinition('layout_paragraphs.settings') + ['mapping' => []]; + $lp_config_schema = $lp_config_schema['mapping']; $form['show_paragraph_labels'] = [ '#type' => 'checkbox', - '#title' => $erl_config_schema['show_paragraph_labels']['label'], - '#description' => $erl_config_schema['show_paragraph_labels']['description'], - '#default_value' => $config->get('show_paragraph_labels'), + '#title' => $lp_config_schema['show_paragraph_labels']['label'], + '#description' => $lp_config_schema['show_paragraph_labels']['description'], + '#default_value' => $lp_config->get('show_paragraph_labels'), ]; + + $form['show_layout_labels'] = [ + '#type' => 'checkbox', + '#title' => $lp_config_schema['show_layout_labels']['label'], + '#description' => $lp_config_schema['show_layout_labels']['description'], + '#default_value' => $lp_config->get('show_layout_labels'), + ]; + return parent::buildForm($form, $form_state); } @@ -83,11 +91,12 @@ class LayoutParagraphsSettingsForm extends ConfigFormBase { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - $config = $this->configFactory()->getEditable('layout_paragraphs.settings'); - $config->set('show_paragraph_labels', $form_state->getValue('show_paragraph_labels')); - $config->save(); + $lp_config = $this->configFactory()->getEditable('layout_paragraphs.settings'); + $lp_config->set('show_paragraph_labels', $form_state->getValue('show_paragraph_labels')); + $lp_config->set('show_layout_labels', $form_state->getValue('show_layout_labels')); + $lp_config->save(); // Confirmation on form submission. - $this->messenger()->addMessage($this->t('The Entity Reference Layout settings have been saved.')); + $this->messenger()->addMessage($this->t('The Layout Paragraphs settings have been saved.')); } } diff --git a/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php b/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php index 94d1b7c462491eb30f4c72329c4e0eb4fae41cb1..d5490ebca23cbb3081769951f74def349450795b 100644 --- a/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php +++ b/src/Plugin/Field/FieldWidget/LayoutParagraphsWidget.php @@ -30,7 +30,6 @@ use Drupal\Core\Entity\EntityDisplayRepositoryInterface; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\OpenDialogCommand; use Drupal\Core\Ajax\AppendCommand; -use Drupal\Core\Ajax\PrependCommand; use Drupal\Core\Ajax\RemoveCommand; use Drupal\Core\Ajax\CloseDialogCommand; use Drupal\Core\Ajax\ReplaceCommand; @@ -38,6 +37,7 @@ use Drupal\paragraphs\ParagraphInterface; use Drupal\paragraphs\ParagraphsTypeInterface; use Drupal\layout_paragraphs\Ajax\LayoutParagraphsStateResetCommand; use Drupal\layout_paragraphs\Ajax\LayoutParagraphsInsertCommand; +use Drupal\Core\Config\ConfigFactoryInterface; /** * Entity Reference with Layout field widget. @@ -137,6 +137,13 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi */ protected $entityDisplayRepository; + /** + * The config factory. + * + * @var \Drupal\Core\config\ConfigFactoryInterface + */ + protected $config; + /** * Indicates whether the current widget instance is in translation. * @@ -173,6 +180,8 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi * The current user. * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository * The entity display repository. + * @param \drupal\Core\Config\ConfigFactoryInterface $config_factory + * The config factory. */ public function __construct( $plugin_id, @@ -187,8 +196,8 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi PluginFormFactoryInterface $plugin_form_manager, LanguageManager $language_manager, AccountProxyInterface $current_user, - EntityDisplayRepositoryInterface $entity_display_repository) { - + EntityDisplayRepositoryInterface $entity_display_repository, + ConfigFactoryInterface $config_factory) { parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings); $this->renderer = $renderer; @@ -200,6 +209,7 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi $this->languageManager = $language_manager; $this->currentUser = $current_user; $this->entityDisplayRepository = $entity_display_repository; + $this->config = $config_factory; } /** @@ -219,7 +229,8 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi $container->get('plugin_form.factory'), $container->get('language_manager'), $container->get('current_user'), - $container->get('entity_display.repository') + $container->get('entity_display.repository'), + $container->get('config.factory') ); } @@ -273,6 +284,8 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi $preview['#attributes']['class'][] = Html::cleanCssIdentifier($entity->uuid() . '-preview'); } + $show_labels = $this->config->get('layout_paragraphs.settings')->get('show_paragraph_labels'); + $element = [ '#widget_item' => TRUE, '#type' => 'container', @@ -349,6 +362,11 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi '#element_parents' => $parents, ], ], + 'label' => $show_labels ? [ + '#type' => 'label', + '#title' => $entity->getParagraphType()->label, + '#attributes' => ['class' => ['paragraph-type-label']], + ] : [], ]; // Nested elements for regions. @@ -741,7 +759,7 @@ class LayoutParagraphsWidget extends WidgetBase implements ContainerFactoryPlugi $element = $elements[$index]; if (!empty($element['#widget_item'])) { $paragraph_elements[$element['#entity']->uuid()] = $element; - // Maintain a hidden flast list of elements to easily locate items. + // Maintain a hidden flat list of elements to easily locate items. $elements['#items'][$element['#entity']->uuid()] = $element; unset($elements[$index]); }