Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conditional_fields
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
conditional_fields
Merge requests
!48
#3063335
: Support for Entity Browser
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
#3063335
: Support for Entity Browser
issue/conditional_fields-3063335:3063335-4
into
4.x
Overview
0
Commits
4
Pipelines
3
Changes
2
Open
April Sides
requested to merge
issue/conditional_fields-3063335:3063335-4
into
4.x
11 months ago
Overview
0
Commits
4
Pipelines
3
Changes
2
Expand
Closes
#3063335
0
0
Merge request reports
Compare
4.x
version 5
b3675e86
2 months ago
version 4
10f1be00
3 months ago
version 3
346defa4
11 months ago
version 2
6db1be74
11 months ago
version 1
118118d1
11 months ago
4.x (HEAD)
and
latest version
latest version
88b4b101
4 commits,
2 months ago
version 5
b3675e86
4 commits,
2 months ago
version 4
10f1be00
4 commits,
3 months ago
version 3
346defa4
3 commits,
11 months ago
version 2
6db1be74
2 commits,
11 months ago
version 1
118118d1
1 commit,
11 months ago
2 files
+
119
−
62
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/ConditionalFieldsElementAlterHelper.php
+
85
−
56
Options
@@ -105,74 +105,103 @@ class ConditionalFieldsElementAlterHelper {
$is_related_to_paragraph
=
(
bool
)
$paragraph_bundle
;
$entity_type
=
$is_related_to_paragraph
?
'paragraph'
:
$entity_type
;
}
}
}
elseif
(
isset
(
$build_info
[
'base_form_id'
])
&&
$build_info
[
'base_form_id'
]
===
'entity_browser_form'
&&
$first_parent
===
'inline_entity_form'
)
{
// If this is an entity_browser_form, we can treat is similar to the
// inline_entity_form. There just isn't a parent entity form like there is
// with a standard inline_entity_form.
if
(
$inline_entity_form_parents
=
ConditionalFieldsFormHelper
::
findInlineEntityFormParentsForElement
(
$full_form
,
$field
))
{
$form
=
&
NestedArray
::
getValue
(
$full_form
,
$inline_entity_form_parents
[
'element_parents'
]);
// Remove outer forms from field parents arrays.
$field
=
ConditionalFieldsFormHelper
::
fieldRemoveInlineEntityFormParents
(
$field
,
$inline_entity_form_parents
);
$ief_entity
=
$form
[
"#entity"
];
$bundle
=
$ief_entity
->
bundle
();
$entity_type
=
$ief_entity
->
getEntityTypeId
();
/**
* @deprecated Not actual from Drupal 8.7.0.
* Media entity returns the actual bundle object, rather than id
*/
if
(
is_object
(
$bundle
)
&&
method_exists
(
$bundle
,
'getPluginId'
))
{
$bundle
=
$bundle
->
getPluginId
();
}
}
}
$dependencies
=
$this
->
loadDependencies
(
$entity_type
,
$bundle
);
if
(
!
isset
(
$entity_type
)
||
!
isset
(
$bundle
))
{
return
$element
;
}
if
(
!
$dependencies
)
{
return
$element
;
}
// We only add requirement on the widget parent and not on child.
if
(
count
(
$field
[
'#array_parents'
])
>
1
&&
$field
[
'#array_parents'
][
count
(
$field
[
'#array_parents'
])
-
2
]
===
'widget'
&&
is_int
(
$field
[
'#array_parents'
][
count
(
$field
[
'#array_parents'
])
-
1
])
)
{
return
$element
;
$dependencies
=
$this
->
loadDependencies
(
$entity_type
,
$bundle
);
if
(
!
$dependencies
)
{
return
$element
;
}
// We only add requirement on the widget parent and not on child.
if
(
count
(
$field
[
'#array_parents'
])
>
1
&&
$field
[
'#array_parents'
][
count
(
$field
[
'#array_parents'
])
-
2
]
===
'widget'
&&
is_int
(
$field
[
'#array_parents'
][
count
(
$field
[
'#array_parents'
])
-
1
])
)
{
return
$element
;
}
$field_name
=
reset
(
$field
[
'#array_parents'
]);
// We get the name of the field inside the paragraph where the
// conditions are being applied, instead of the field name where the
// paragraph is.
if
(
$is_related_to_paragraph
)
{
foreach
(
$field
[
'#array_parents'
]
as
$parent
)
{
if
(
isset
(
$dependencies
[
'dependents'
][
$parent
]))
{
$field_name
=
$parent
;
break
;
}
$field_name
=
reset
(
$field
[
'#array_parents'
]);
// We get the name of the field inside the the paragraph where the
// conditions are being applied, instead of the field name where the
// paragraph is.
if
(
$is_related_to_paragraph
)
{
foreach
(
$field
[
'#array_parents'
]
as
$parent
)
{
if
(
isset
(
$dependencies
[
'dependents'
][
$parent
]))
{
$field_name
=
$parent
;
break
;
}
if
(
isset
(
$dependencies
[
'dependees'
][
$parent
]))
{
$field_name
=
$parent
;
break
;
}
}
if
(
$parent
!=
$field_name
||
$first_parent
==
$field_name
||
!
isset
(
$field
[
'#type'
]))
{
return
$elem
ent
;
}
if
(
isset
(
$dependencies
[
'dependees'
][
$parent
]))
{
$field_name
=
$par
ent
;
break
;
}
}
$paragraph_info
=
[];
1 Code Quality finding detected
major:
Variable $parent might not be defined
if
(
$parent
!=
$field_name
||
$first_parent
==
$field_name
||
!
isset
(
$field
[
'#type'
]))
{
return
$element
;
}
}
if
(
$is_related_to_paragraph
)
{
$paragraph_info
[
'entity_type'
]
=
$entity_type
;
$paragraph_info
[
'bundle'
]
=
$bundle
;
$paragraph_info
[
'paragraph_field'
]
=
$first_parent
;
$paragraph_info
[
'array_parents'
]
=
$element
[
'#array_parents'
];
}
$paragraph_info
=
[];
// Attach dependent.
if
(
isset
(
$dependencies
[
'dependents'
][
$field_name
]))
{
foreach
(
$dependencies
[
'dependents'
][
$field_name
]
as
$id
=>
$dependency
)
{
if
(
!
isset
(
$form
[
'#conditional_fields'
][
$field_name
][
'dependees'
][
$id
])
||
$this
->
isPriorityField
(
$field
))
{
if
(
$is_related_to_paragraph
)
{
$paragraph_info
[
'field'
]
=
$field_name
;
}
$this
->
attachDependency
(
$form
,
$form_state
,
[
'#field_name'
=>
$dependency
[
'dependee'
]],
$field
,
$dependency
[
'options'
],
$id
,
$paragraph_info
);
}
if
(
$is_related_to_paragraph
)
{
$paragraph_info
[
'entity_type'
]
=
$entity_type
;
$paragraph_info
[
'bundle'
]
=
$bundle
;
$paragraph_info
[
'paragraph_field'
]
=
$first_parent
;
$paragraph_info
[
'array_parents'
]
=
$element
[
'#array_parents'
];
}
// Attach dependent.
if
(
isset
(
$dependencies
[
'dependents'
][
$field_name
]))
{
foreach
(
$dependencies
[
'dependents'
][
$field_name
]
as
$id
=>
$dependency
)
{
if
(
!
isset
(
$form
[
'#conditional_fields'
][
$field_name
][
'dependees'
][
$id
])
||
$this
->
isPriorityField
(
$field
))
{
if
(
$is_related_to_paragraph
)
{
$paragraph_info
[
'field'
]
=
$field_name
;
}
1 Code Quality finding detected
major:
Variable $form might not be defined
$this
->
attachDependency
(
$form
,
$form_state
,
[
'#field_name'
=>
$dependency
[
'dependee'
]],
$field
,
$dependency
[
'options'
],
$id
,
$paragraph_info
);
}
}
}
// Attach dependee.
if
(
isset
(
$dependencies
[
'dependees'
][
$field_name
]))
{
foreach
(
$dependencies
[
'dependees'
][
$field_name
]
as
$id
=>
$dependency
)
{
if
(
!
isset
(
$form
[
'#conditional_fields'
][
$field_name
][
'dependents'
][
$id
])
||
$this
->
isPriorityField
(
$field
))
{
if
(
$is_related_to_paragraph
)
{
$paragraph_info
[
'field'
]
=
$field_name
;
}
$this
->
attachDependency
(
$form
,
$form_state
,
$field
,
[
'#field_name'
=>
$dependency
[
'dependent'
]],
$dependency
[
'options'
],
$id
,
$paragraph_info
);
}
// Attach dependee.
if
(
isset
(
$dependencies
[
'dependees'
][
$field_name
]))
{
foreach
(
$dependencies
[
'dependees'
][
$field_name
]
as
$id
=>
$dependency
)
{
if
(
!
isset
(
$form
[
'#conditional_fields'
][
$field_name
][
'dependents'
][
$id
])
||
$this
->
isPriorityField
(
$field
))
{
if
(
$is_related_to_paragraph
)
{
$paragraph_info
[
'field'
]
=
$field_name
;
}
1 Code Quality finding detected
major:
Variable $form might not be defined
$this
->
attachDependency
(
$form
,
$form_state
,
$field
,
[
'#field_name'
=>
$dependency
[
'dependent'
]],
$dependency
[
'options'
],
$id
,
$paragraph_info
);
}
}
}
Loading