Commit ab0011dd authored by git's avatar git Committed by miro_dietiker

Issue #2668678 by yongt9412: Make paragraphs widget the default for paragraphs fields

parent 6e7b8322
......@@ -75,6 +75,33 @@ function paragraphs_theme_suggestions_paragraph(array $variables) {
return $suggestions;
}
/**
* Implements hook_form_FORM_ID_alter().
*/
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']);
// Loop over ERR field's display options with paragraph target type.
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') {
foreach (['options_buttons', 'options_select', 'entity_reference_revisions_autocomplete'] as $option) {
unset($form['fields'][$field_name]['plugin']['type']['#options'][$option]);
}
}
}
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function paragraphs_form_field_storage_config_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if ($form_state->getFormObject()->getEntity()->getType() == 'entity_reference') {
// Entity Reference fields are no longer supported to reference Paragraphs.
unset($form['settings']['target_type']['#options'][(string) t('Content')]['paragraph']);
}
}
/**
* Prepares variables for paragraph templates.
*
......
......@@ -440,6 +440,23 @@ class ParagraphsAdministrationTest extends WebTestBase {
$this->drupalPostForm(NULL, $edit, t('Save and publish'));
$this->assertRaw('<em class="placeholder">test required</em> 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);
$this->assertRaw('value="entity_reference_paragraphs" selected="selected"');
// Check that Paragraphs is not displayed as an entity_reference field
// reference option.
$this->drupalGet('admin/structure/types/manage/article/fields/add-field');
$edit = [
'new_storage_type' => 'entity_reference',
'label' => 'unsupported field',
'field_name' => 'unsupportedfield',
];
$this->drupalPostForm(NULL, $edit, t('Save and continue'));
$this->assertNoOption('edit-settings-target-type', 'paragraph');
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment