- Issue created by @marieAscomedia
- Status changed to Needs work
about 1 year ago 12:14pm 27 September 2023 - π³π±Netherlands jaapjan
Which version of the patch did you use before? In our site we used https://www.drupal.org/files/issues/2019-01-17/extra_field-using_in_form... β . Here you can see (in ExtraFieldFormManager::entityView) that the plugin element was always returned inside a new form field of type container with a widget. Like so:
$element = $plugin->formView($form, $form_state); if (!empty($element)) { $form[$field_name] = [ '#weight' => $extra_field['weight'], '#type' => 'container', 'widget' => $element, ]; }
But in the new 2.x version the element is printed directly. See FormManager.php::entityFormAlter, line 133:
$form[$fieldName] = $plugin->formElement($form, $formState);
Going back to your example extra field plugin (ExampleMarkup):
Current code is:
/** * {@inheritdoc} */ public function formElement(array &$form, FormStateInterface $form_state) { $element['markup'] = ['#markup' => '<p>Hello world 1</p>']; $element['container'] = [ '#type' => 'container', '#markup' => '<p>Hello world 2</p>', ]; $element['item'] = [ '#type' => 'item', '#title' => 'Greeting', '#markup' => '<p>Hello world 3</p>', '#description' => "A common line of example output.", ]; return $element; }
It will fix the problem if you change this to:
/** * {@inheritdoc} */ public function formElement(array &$form, FormStateInterface $form_state) { $element['markup'] = ['#markup' => '<p>Hello world 1</p>']; $element['container'] = [ '#type' => 'container', '#markup' => '<p>Hello world 2</p>', ]; $element['item'] = [ '#type' => 'item', '#title' => 'Greeting', '#markup' => '<p>Hello world 3</p>', '#description' => "A common line of example output.", ]; return [ '#type' => 'container', 'widget' => $element, ]; }
I think this means that we have two options:
1. Developer is responsible for adding a type to your extra_field element. We should probably add this in the examples if we go down this route.
2. Restore the way the element is added to the form, like in patch 24 or add a fallback when there is no #type provided we add type 'container' to the render array. This may have some impact on existing installations using the 2.x branch of this module.Curious to hear what the maintainers think of this.
It seem that I use this version of the patch :
https://www.drupal.org/files/issues/2019-07-31/extra_field-using_in_form... βI will try your option with the container and let you know the result.
Thank you.- πͺπΈSpain pcambra Asturies
This is probably more a documentation/example than anything that the module needs to do, maybe we could add a simple element with field_group example?
- πͺπΈSpain enchufe Spain
Thank you #3 β¨ Compatibility with field group Needs work ! Your documentation worked for me out of the box.
- πΊπΈUnited States mlncn Minneapolis, MN, USA
We have a module built on Extra Field Plus (and friends) - https://www.drupal.org/project/create_referencing_content β - that seems to be running into this for entity view display, not only the form as described here, with Field Group 3.x. Is there any similar special markup as described here for the widget that that needs to be part of the formatter for it to work as expected?
I'm pretty confused about this issue too⦠definitely needs either better documentation across the Extra Field ecosystem or if Extra Field can non-intrusively ensure pseudofields always work with Field Group module, that's ideal?