Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
paragraphs
Commits
ab0011dd
Commit
ab0011dd
authored
May 09, 2016
by
git
Committed by
Miro Dietiker
May 09, 2016
Browse files
Issue
#2668678
by yongt9412: Make paragraphs widget the default for paragraphs fields
parent
6e7b8322
Changes
2
Hide whitespace changes
Inline
Side-by-side
paragraphs.module
View file @
ab0011dd
...
...
@@ -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.
*
...
...
src/Tests/ParagraphsAdministrationTest.php
View file @
ab0011dd
...
...
@@ -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'
);
}
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment