Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
paragraphs
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
paragraphs
Commits
ab0011dd
Commit
ab0011dd
authored
8 years ago
by
git
Committed by
Miro Dietiker
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2668678
by yongt9412: Make paragraphs widget the default for paragraphs fields
parent
6e7b8322
No related branches found
Branches containing commit
Tags
8.x-1.0
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
paragraphs.module
+27
-0
27 additions, 0 deletions
paragraphs.module
src/Tests/ParagraphsAdministrationTest.php
+17
-0
17 additions, 0 deletions
src/Tests/ParagraphsAdministrationTest.php
with
44 additions
and
0 deletions
paragraphs.module
+
27
−
0
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.
*
...
...
This diff is collapsed.
Click to expand it.
src/Tests/ParagraphsAdministrationTest.php
+
17
−
0
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'
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment