From dce888fb0dfb95aed37f37f9411ba25c7a442ad7 Mon Sep 17 00:00:00 2001 From: golddragon007 Date: Wed, 22 Nov 2017 14:51:51 +0100 Subject: [PATCH] Add 'Add ' string/text to entity reference add button --- ...m_display.paragraph.text_boxes.default.yml | 1 + parade.install | 10 +++ .../InlineParagraphsPreviewerWidget.php | 9 ++- .../FieldWidget/InlineParagraphsWidget.php | 64 +++++++++++++++++++ 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php diff --git a/config/optional/core.entity_form_display.paragraph.text_boxes.default.yml b/config/optional/core.entity_form_display.paragraph.text_boxes.default.yml index 2779dc2..27284c8 100644 --- a/config/optional/core.entity_form_display.paragraph.text_boxes.default.yml +++ b/config/optional/core.entity_form_display.paragraph.text_boxes.default.yml @@ -116,6 +116,7 @@ content: add_mode: dropdown form_display_mode: default default_paragraph_type: '' + add_text_needed: '1' third_party_settings: { } region: content parade_text: diff --git a/parade.install b/parade.install index 528b42a..c4304c1 100644 --- a/parade.install +++ b/parade.install @@ -188,3 +188,13 @@ function parade_update_8203() { } } } + +/** + * Add new option (add_text_needed) default value. + */ +function parade_update_8204() { + $config_factory = \Drupal::configFactory(); + $config_factory->getEditable('core.entity_form_display.paragraph.text_boxes.default') + ->set('content.parade_paragraphs.settings.add_text_needed', '1') + ->save(); +} diff --git a/src/Plugin/Field/FieldWidget/InlineParagraphsPreviewerWidget.php b/src/Plugin/Field/FieldWidget/InlineParagraphsPreviewerWidget.php index 43891cd..e114653 100644 --- a/src/Plugin/Field/FieldWidget/InlineParagraphsPreviewerWidget.php +++ b/src/Plugin/Field/FieldWidget/InlineParagraphsPreviewerWidget.php @@ -11,7 +11,7 @@ use Drupal\Core\Entity\ContentEntityBase; use Drupal\Core\Ajax\OpenModalDialogCommand; use Drupal\Core\Field\FieldItemListInterface; -use Drupal\paragraphs\Plugin\Field\FieldWidget\InlineParagraphsWidget; +use Drupal\parade\Plugin\Field\FieldWidget\InlineParagraphsWidget; /** * Plugin implementation of the 'Paragraphs with preview' widget. @@ -158,8 +158,11 @@ public function formMultipleElements(FieldItemListInterface $items, array &$form */ protected function buildButtonsAddMode() { $add_more_elements = parent::buildButtonsAddMode(); - foreach ($this->getAccessibleOptions() as $machine_name => $label) { - $add_more_elements['add_more_button_' . $machine_name]['#value'] = $label; + // Do not run this, if we need the 'Add ' string. + if (!$this->getSetting('add_text_needed')) { + foreach ($this->getAccessibleOptions() as $machine_name => $label) { + $add_more_elements['add_more_button_' . $machine_name]['#value'] = $label; + } } $add_more_elements['#theme_wrappers'] = ['parade__paragraphs_dropbutton_wrapper']; $add_more_elements['#label'] = [ diff --git a/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php new file mode 100644 index 0000000..4157ddc --- /dev/null +++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php @@ -0,0 +1,64 @@ + 'checkbox', + '#title' => $this->t("Add 'Add ' text before title on entity add buttons."), + '#default_value' => $this->getSetting('add_text_needed'), + '#weight' => 2, + ); + + return $elements; + } + + /** + * {@inheritdoc} + */ + public function settingsSummary() { + $summary = parent::settingsSummary(); + + // New values. + $summary[] = $this->t("'Add ' text will be added before title?: @answer", ['@answer' => $this->getSetting('add_text_needed') ? 'Yes' : 'No']); + + return $summary; + } +} \ No newline at end of file