diff --git a/paragraphs.module b/paragraphs.module index 190e470..c644ee9 100644 --- a/paragraphs.module +++ b/paragraphs.module @@ -80,17 +80,13 @@ function paragraphs_theme_suggestions_paragraph(array $variables) { */ function paragraphs_form_entity_form_display_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { $field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($form['#entity_type'], $form['#bundle']); - foreach ($field_definitions as $key => $value) { - if ($field_definitions[$key]->getType() == 'entity_reference_revisions') { - if ($field_definitions[$key]->getSettings()['target_type'] == 'paragraph') { + foreach (array_keys($field_definitions) as $field_name) { + if ($field_definitions[$field_name]->getType() == 'entity_reference_revisions') { + if ($field_definitions[$field_name]->getSettings()['target_type'] == 'paragraph') { // Loop over the display options of an err field with paragraph target // type. - foreach ($form['fields'][$key]['plugin']['type']['#options'] as $option => $value) { - // Unset the widget display options that are no longer supported for - // the Paragraphs field. - if (in_array($option, ['options_buttons', 'options_select', 'entity_reference_revisions_autocomplete'])) { - unset($form['fields'][$key]['plugin']['type']['#options'][$option]); - } + foreach (['options_buttons', 'options_select', 'entity_reference_revisions_autocomplete'] as $option) { + unset($form['fields'][$field_name]['plugin']['type']['#options'][$option]); } } } diff --git a/src/Tests/ParagraphsAdministrationTest.php b/src/Tests/ParagraphsAdministrationTest.php index 1082c85..8acbba7 100644 --- a/src/Tests/ParagraphsAdministrationTest.php +++ b/src/Tests/ParagraphsAdministrationTest.php @@ -441,13 +441,13 @@ class ParagraphsAdministrationTest extends WebTestBase { $this->assertRaw('test required has been created.'); $this->assertNoRaw('This value should not be null.'); + // 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), 2); - // @todo Remove assert raw and uncomment assertOptionSelected after https://www.drupal.org/node/2530092 $this->assertRaw('value="entity_reference_paragraphs" selected="selected"'); - //$this->assertOptionSelected('fields[field_paragraphs][type]', 'entity_reference_paragraphs'); + // Test that entity_reference field is not supported to Paragraphs. $this->drupalGet('admin/structure/types/manage/article/fields/add-field'); $edit = [ 'new_storage_type' => 'entity_reference',