diff --git a/config/schema/paragraphs_type.schema.yml b/config/schema/paragraphs_type.schema.yml
index a04f6c2..403fe63 100644
--- a/config/schema/paragraphs_type.schema.yml
+++ b/config/schema/paragraphs_type.schema.yml
@@ -57,3 +57,19 @@ field.widget.settings.entity_reference_paragraphs:
type: string
default_paragraph_type:
type: string
+
+field.widget.settings.paragraphs:
+ type: mapping
+ mapping:
+ title:
+ type: string
+ title_plural:
+ type: string
+ edit_mode:
+ type: string
+ add_mode:
+ type: string
+ form_display_mode:
+ type: string
+ default_paragraph_type:
+ type: string
diff --git a/css/paragraphs.admin.css b/css/paragraphs.admin.css
index 704c45c..58971cc 100644
--- a/css/paragraphs.admin.css
+++ b/css/paragraphs.admin.css
@@ -80,42 +80,3 @@
padding-right: 10px;
text-align: right;
}
-
-.paragraphs-remove-button-container {
- display: flex;
- flex-flow: row-reverse;
- padding-left: 1em;
- padding-right: 1em;
- margin-left: auto;
-}
-
-.js .paragraphs-remove-button {
- background: url('/core/misc/icons/787878/ex.svg') no-repeat center;
- background-size: 13px 13px;
- width: 20px;
- border: none;
- font-size: 0px;
- line-height: 0;
-}
-
-.js .paragraphs-remove-button:hover {
- background: url('/core/misc/icons/000000/ex.svg') no-repeat center;
- background-size: 13px 13px;
- width: 20px;
- border: none;
- font-size: 0px;
- line-height: 0;
- box-shadow: none;
-}
-
-
-/* Override 600px breakpoint core submit button tweaks. */
-@media screen and (max-width: 600px) {
- .js .paragraphs-remove-button-container .paragraphs-remove-button {
- width: 20px;
- }
-
- .js .paragraphs-remove-button-container .paragraphs-remove-button:hover {
- width: 20px;
- }
-}
diff --git a/css/paragraphs.experimental.css b/css/paragraphs.experimental.css
new file mode 100644
index 0000000..a54eb60
--- /dev/null
+++ b/css/paragraphs.experimental.css
@@ -0,0 +1,76 @@
+.js .field--widget-paragraphs .dropbutton-wrapper {
+ display: inline-flex;
+ padding-right: 0em;
+ margin-right: 0em;
+ /* Override 600px breakpoint from core. */
+ width: auto;
+}
+
+.js .field--widget-paragraphs .dropbutton-widget {
+ position: relative;
+}
+
+.js .field--widget-paragraphs .field-multiple-table {
+ margin-bottom: 10px;
+}
+
+.js .field--widget-paragraphs td {
+ padding: 10px 0px 10px 0px;
+}
+
+.js .field--widget-paragraphs .field-multiple-drag {
+ vertical-align: top;
+}
+.js .field--widget-paragraphs .draggable .tabledrag-handle {
+ padding-right: 0;
+ margin-left: 0;
+}
+.js .field--widget-paragraphs .tabledrag-handle .handle {
+ margin-left: 0;
+ margin-right: 0;
+ padding-right: 0.2em;
+}
+
+.js .field--widget-paragraphs .delta-order {
+ padding-right: 10px;
+ text-align: right;
+}
+
+.paragraphs-remove-button-container {
+ display: flex;
+ flex-flow: row-reverse;
+ padding-left: 1em;
+ padding-right: 1em;
+ margin-left: auto;
+}
+
+.js .paragraphs-remove-button {
+ background: url('/core/misc/icons/787878/ex.svg') no-repeat center;
+ background-size: 13px 13px;
+ width: 20px;
+ border: none;
+ font-size: 0px;
+ line-height: 0;
+}
+
+.js .paragraphs-remove-button:hover {
+ background: url('/core/misc/icons/000000/ex.svg') no-repeat center;
+ background-size: 13px 13px;
+ width: 20px;
+ border: none;
+ font-size: 0px;
+ line-height: 0;
+ box-shadow: none;
+}
+
+/* Override 600px breakpoint core submit button tweaks. */
+@media screen and (max-width: 600px) {
+ .js .paragraphs-remove-button-container .paragraphs-remove-button {
+ width: 20px;
+ }
+
+ .js .paragraphs-remove-button-container .paragraphs-remove-button:hover {
+ width: 20px;
+ }
+}
+
diff --git a/paragraphs.libraries.yml b/paragraphs.libraries.yml
index 1ac3b50..543dc66 100644
--- a/paragraphs.libraries.yml
+++ b/paragraphs.libraries.yml
@@ -10,4 +10,9 @@ drupal.paragraphs.admin:
- core/drupal.dropbutton
css:
theme:
- css/paragraphs.admin.css: {}
\ No newline at end of file
+ css/paragraphs.admin.css: {}
+
+drupal.paragraphs.experimental:
+ css:
+ theme:
+ css/paragraphs.experimental.css: {}
diff --git a/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
index 1f36cf9..0992c98 100644
--- a/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
+++ b/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php
@@ -25,8 +25,8 @@ use Symfony\Component\Validator\ConstraintViolationInterface;
*
* @FieldWidget(
* id = "entity_reference_paragraphs",
- * label = @Translation("Paragraphs"),
- * description = @Translation("An paragraphs inline form widget."),
+ * label = @Translation("Paragraphs Classic"),
+ * description = @Translation("A paragraphs inline form widget."),
* field_types = {
* "entity_reference_revisions"
* }
@@ -39,7 +39,7 @@ class InlineParagraphsWidget extends WidgetBase {
*
* @var bool
*/
- private $isTranslating;
+ protected $isTranslating;
/**
* Id to name ajax buttons that includes field parents and field name.
@@ -384,65 +384,11 @@ class InlineParagraphsWidget extends WidgetBase {
'#markup' => $bundle_info['label'],
);
- // Hide the button when translating.
- $button_access = $paragraphs_entity->access('delete') && !$this->isTranslating;
- $element['top']['paragraphs_remove_button_container'] = [
- '#type' => 'container',
- '#weight' => 1,
- '#attributes' => [
- 'class' => [
- 'paragraphs-remove-button-container',
- ],
- ],
- 'paragraphs_remove_button' => [
- '#type' => 'submit',
- '#value' => $this->t('Remove'),
- '#name' => strtr($id_prefix, '-', '_') . '_remove',
- '#weight' => 500,
- '#attributes' => [
- 'class' => [
- 'paragraphs-remove-button',
- ],
- ],
- '#submit' => array(array(get_class($this), 'paragraphsItemSubmit')),
- '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))),
- '#delta' => $delta,
- '#ajax' => array(
- 'callback' => array(get_class($this), 'itemAjax'),
- 'wrapper' => $widget_state['ajax_wrapper_id'],
- 'effect' => 'fade',
- ),
- '#access' => $button_access,
- '#paragraphs_mode' => 'remove',
- ]
- ];
+ $links = $this->buildActionButtons($items, $item_mode, $paragraphs_entity, $id_prefix, $delta);
$actions = array();
- $links = array();
if ($item_mode == 'edit') {
-
- if (isset($items[$delta]->entity) && ($default_edit_mode == 'preview' || $default_edit_mode == 'closed')) {
- $links['collapse_button'] = array(
- '#type' => 'submit',
- '#value' => $this->t('Collapse'),
- '#name' => strtr($id_prefix, '-', '_') . '_collapse',
- '#weight' => 499,
- '#submit' => array(array(get_class($this), 'paragraphsItemSubmit')),
- '#delta' => $delta,
- '#ajax' => array(
- 'callback' => array(get_class($this), 'itemAjax'),
- 'wrapper' => $widget_state['ajax_wrapper_id'],
- 'effect' => 'fade',
- ),
- '#access' => $paragraphs_entity->access('update'),
- '#prefix' => '
',
- '#suffix' => '',
- '#paragraphs_mode' => 'collapsed',
- '#paragraphs_show_warning' => TRUE,
- );
- }
-
$info['edit_button_info'] = array(
'#type' => 'container',
'#markup' => $this->t('You are not allowed to edit this @title.', array('@title' => $this->getSetting('title'))),
@@ -465,25 +411,6 @@ class InlineParagraphsWidget extends WidgetBase {
);
}
elseif ($item_mode == 'preview' || $item_mode == 'closed') {
- $links['edit_button'] = array(
- '#type' => 'submit',
- '#value' => $this->t('Edit'),
- '#name' => strtr($id_prefix, '-', '_') . '_edit',
- '#weight' => 501,
- '#submit' => array(array(get_class($this), 'paragraphsItemSubmit')),
- '#limit_validation_errors' => array(array_merge($parents, array($field_name, 'add_more'))),
- '#delta' => $delta,
- '#ajax' => array(
- 'callback' => array(get_class($this), 'itemAjax'),
- 'wrapper' => $widget_state['ajax_wrapper_id'],
- 'effect' => 'fade',
- ),
- '#access' => $paragraphs_entity->access('update'),
- '#prefix' => '',
- '#suffix' => '',
- '#paragraphs_mode' => 'edit',
- );
-
if ($show_must_be_saved_warning) {
$info['must_be_saved_info'] = array(
'#type' => 'container',
@@ -521,9 +448,9 @@ class InlineParagraphsWidget extends WidgetBase {
);
}
- if (count($links)) {
+ if (count($links['links'])) {
$show_links = 0;
- foreach($links as $link_item) {
+ foreach($links['links'] as $link_item) {
if (!isset($link_item['#access']) || $link_item['#access']) {
$show_links++;
}
@@ -531,7 +458,7 @@ class InlineParagraphsWidget extends WidgetBase {
if ($show_links > 0) {
- $element['top']['links'] = $links;
+ $element['top'] += $links;
if ($show_links > 1) {
$element['top']['links']['#theme_wrappers'] = array('dropbutton_wrapper', 'paragraphs_dropbutton_wrapper');
$element['top']['links']['prefix'] = array(
@@ -545,7 +472,7 @@ class InlineParagraphsWidget extends WidgetBase {
}
else {
$element['top']['links']['#theme_wrappers'] = array('paragraphs_dropbutton_wrapper');
- foreach($links as $key => $link_item) {
+ foreach($links['links'] as $key => $link_item) {
unset($element['top']['links'][$key]['#prefix']);
unset($element['top']['links'][$key]['#suffix']);
}
@@ -892,6 +819,96 @@ class InlineParagraphsWidget extends WidgetBase {
}
/**
+ * Builds the widget actions.
+ *
+ * @return array
+ * Array of buttons that are used for editing, collapsing and removing
+ * paragraphs.
+ */
+ public function buildActionButtons($items, $item_mode, $paragraphs_entity, $id_prefix, $delta) {
+ $links = [];
+ $default_edit_mode = $this->getSetting('edit_mode');
+ $field_name = $this->fieldDefinition->getName();
+ $parents = $this->fieldParents;
+
+ // Hide the button when translating.
+ $button_access = $paragraphs_entity->access('delete') && !$this->isTranslating;
+ $links['links']['remove_button'] = array(
+ '#type' => 'submit',
+ '#value' => $this->t('Remove'),
+ '#name' => strtr($id_prefix, '-', '_') . '_remove',
+ '#weight' => 500,
+ '#submit' => array(array(get_class($this), 'paragraphsItemSubmit')),
+ '#limit_validation_errors' => array(
+ array_merge($parents, array(
+ $field_name,
+ 'add_more'
+ ))
+ ),
+ '#delta' => $delta,
+ '#ajax' => array(
+ 'callback' => array(get_class($this), 'itemAjax'),
+ 'wrapper' => $this->fieldWrapperId,
+ 'effect' => 'fade',
+ ),
+ '#access' => $button_access,
+ '#prefix' => '',
+ '#suffix' => '',
+ '#paragraphs_mode' => 'remove',
+ );
+
+ if ($item_mode == 'edit') {
+ if (isset($items[$delta]->entity) && ($default_edit_mode == 'preview' || $default_edit_mode == 'closed')) {
+ $links['links']['collapse_button'] = array(
+ '#type' => 'submit',
+ '#value' => $this->t('Collapse'),
+ '#name' => strtr($id_prefix, '-', '_') . '_collapse',
+ '#weight' => 499,
+ '#submit' => array(array(get_class($this), 'paragraphsItemSubmit')),
+ '#delta' => $delta,
+ '#ajax' => array(
+ 'callback' => array(get_class($this), 'itemAjax'),
+ 'wrapper' => $this->fieldWrapperId,
+ 'effect' => 'fade',
+ ),
+ '#access' => $paragraphs_entity->access('update'),
+ '#prefix' => '',
+ '#suffix' => '',
+ '#paragraphs_mode' => 'collapsed',
+ '#paragraphs_show_warning' => TRUE,
+ );
+ }
+ }
+ elseif ($item_mode == 'preview' || $item_mode == 'closed') {
+ $links['links']['edit_button'] = array(
+ '#type' => 'submit',
+ '#value' => $this->t('Edit'),
+ '#name' => strtr($id_prefix, '-', '_') . '_edit',
+ '#weight' => 499,
+ '#submit' => array(array(get_class($this), 'paragraphsItemSubmit')),
+ '#limit_validation_errors' => array(
+ array_merge($parents, array(
+ $field_name,
+ 'add_more'
+ ))
+ ),
+ '#delta' => $delta,
+ '#ajax' => array(
+ 'callback' => array(get_class($this), 'itemAjax'),
+ 'wrapper' => $this->fieldWrapperId,
+ 'effect' => 'fade',
+ ),
+ '#access' => $paragraphs_entity->access('update'),
+ '#prefix' => '',
+ '#suffix' => '',
+ '#paragraphs_mode' => 'edit',
+ );
+ }
+
+ return $links;
+ }
+
+ /**
* Add 'add more' button, if not working with a programmed form.
*
* @return array
diff --git a/src/Plugin/Field/FieldWidget/ParagraphsWidget.php b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
new file mode 100644
index 0000000..15ceb6d
--- /dev/null
+++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
@@ -0,0 +1,72 @@
+fieldDefinition->getName();
+ $button_access = $paragraphs_entity->access('delete') && !$this->isTranslating;
+ $links['paragraphs_remove_button_container'] = [
+ '#type' => 'container',
+ '#weight' => 1,
+ '#attributes' => [
+ 'class' => [
+ 'paragraphs-remove-button-container',
+ ],
+ ],
+ 'paragraphs_remove_button' => [
+ '#type' => 'submit',
+ '#value' => $this->t('Remove'),
+ '#name' => strtr($id_prefix, '-', '_') . '_remove',
+ '#weight' => 500,
+ '#attributes' => [
+ 'class' => [
+ 'paragraphs-remove-button',
+ ],
+ ],
+ '#submit' => [[get_class($this), 'paragraphsItemSubmit']],
+ '#limit_validation_errors' => [array_merge($this->fieldParents, [$field_name, 'add_more'])],
+ '#delta' => $delta,
+ '#ajax' => array(
+ 'callback' => array(get_class($this), 'itemAjax'),
+ 'wrapper' => $this->fieldWrapperId,
+ 'effect' => 'fade',
+ ),
+ '#access' => $button_access,
+ '#paragraphs_mode' => 'remove',
+ ]
+ ];
+
+ return $links;
+ }
+}
diff --git a/src/Tests/ParagraphsAdministrationTest.php b/src/Tests/ParagraphsAdministrationTest.php
index 911c2f9..891fa8b 100644
--- a/src/Tests/ParagraphsAdministrationTest.php
+++ b/src/Tests/ParagraphsAdministrationTest.php
@@ -392,7 +392,7 @@ class ParagraphsAdministrationTest extends ParagraphsTestBase {
// Test that unsupported widgets are not displayed.
$this->drupalGet('admin/structure/types/manage/article/form-display');
$select = $this->xpath('//*[@id="edit-fields-field-paragraphs-type"]')[0];
- $this->assertEqual(count($select->option), 1);
+ $this->assertEqual(count($select->option), 2);
$this->assertRaw('value="entity_reference_paragraphs" selected="selected"');
// Check that Paragraphs is not displayed as an entity_reference field