function _field_test_alter_widget
Same name in other branches
- 8.9.x core/modules/field/tests/modules/field_test/field_test.module \_field_test_alter_widget()
- 10 core/modules/field/tests/modules/field_test/field_test.module \_field_test_alter_widget()
- 11.x core/modules/field/tests/modules/field_test/field_test.module \_field_test_alter_widget()
Sets up alterations for widget alter tests.
See also
\Drupal\field\Tests\FormTest::widgetAlterTest()
3 calls to _field_test_alter_widget()
- field_test_field_widget_complete_form_alter in core/
modules/ field/ tests/ modules/ field_test/ field_test.module - Implements hook_field_widget_complete_form_alter().
- field_test_field_widget_complete_test_field_widget_multiple_form_alter in core/
modules/ field/ tests/ modules/ field_test/ field_test.module - Implements hook_field_widget_complete_WIDGET_TYPE_form_alter().
- field_test_field_widget_complete_test_field_widget_multiple_single_value_form_alter in core/
modules/ field/ tests/ modules/ field_test/ field_test.module - Implements hook_field_widget_complete_WIDGET_TYPE_form_alter().
File
-
core/
modules/ field/ tests/ modules/ field_test/ field_test.module, line 138
Code
function _field_test_alter_widget($hook, array &$field_widget_complete_form, FormStateInterface $form_state, array $context) {
$elements =& $field_widget_complete_form['widget'];
// Set a message if this is for the form displayed to set default value for
// the field.
if ($context['default']) {
\Drupal::messenger()->addStatus("From {$hook}(): Default form is true.");
}
$alter_info = \Drupal::state()->get("field_test.widget_alter_test");
$name = $context['items']->getFieldDefinition()
->getName();
if (!empty($alter_info) && $hook === $alter_info['hook'] && $name === $alter_info['field_name']) {
$elements['#prefix'] = "From {$hook}(): prefix on {$name} parent element.";
foreach (Element::children($elements) as $delta => $element) {
$elements[$delta]['#suffix'] = "From {$hook}(): suffix on {$name} child element.";
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.