Skip to content
Snippets Groups Projects

#3063335: Support for Entity Browser

Open April Sides requested to merge issue/conditional_fields-3063335:3063335-4 into 4.x
Files
2
@@ -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 $element;
}
if (isset($dependencies['dependees'][$parent])) {
$field_name = $parent;
break;
}
}
$paragraph_info = [];
  • 1 Code Quality finding detected
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
$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
$this->attachDependency($form, $form_state, $field, ['#field_name' => $dependency['dependent']], $dependency['options'], $id, $paragraph_info);
}
}
}
Loading