X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ffield%2Ftests%2Fmodules%2Ffield_test%2Ffield_test.module;fp=web%2Fcore%2Fmodules%2Ffield%2Ftests%2Fmodules%2Ffield_test%2Ffield_test.module;h=1d7e2d6312d399783fbc856bd8c2c5d553d2b7a3;hp=cc1f9fa9054a31a79ec2e73e7fc8c0e3ddf25ebd;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/field/tests/modules/field_test/field_test.module b/web/core/modules/field/tests/modules/field_test/field_test.module index cc1f9fa90..1d7e2d631 100644 --- a/web/core/modules/field/tests/modules/field_test/field_test.module +++ b/web/core/modules/field/tests/modules/field_test/field_test.module @@ -15,6 +15,7 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Render\Element; use Drupal\field\FieldStorageConfigInterface; require_once __DIR__ . '/field_test.entity.inc'; @@ -100,16 +101,6 @@ function field_test_entity_display_build_alter(&$output, $context) { * Implements hook_field_widget_form_alter(). */ function field_test_field_widget_form_alter(&$element, FormStateInterface $form_state, $context) { - $field_definition = $context['items']->getFieldDefinition(); - switch ($field_definition->getName()) { - case 'alter_test_text': - drupal_set_message('Field size: ' . $context['widget']->getSetting('size')); - break; - - case 'alter_test_options': - drupal_set_message('Widget type: ' . $context['widget']->getPluginId()); - break; - } // Set a message if this is for the form displayed to set default value for // the field. if ($context['default']) { @@ -117,6 +108,50 @@ function field_test_field_widget_form_alter(&$element, FormStateInterface $form_ } } +/** + * Implements hook_field_widget_multivalue_form_alter(). + */ +function field_test_field_widget_multivalue_form_alter(array &$elements, FormStateInterface $form_state, array $context) { + _field_test_alter_widget("hook_field_widget_multivalue_form_alter", $elements, $form_state, $context); +} + +/** + * Implements hook_field_widget_multivalue_WIDGET_TYPE_form_alter(). + */ +function field_test_field_widget_multivalue_test_field_widget_multiple_form_alter(array &$elements, FormStateInterface $form_state, array $context) { + _field_test_alter_widget("hook_field_widget_multivalue_WIDGET_TYPE_form_alter", $elements, $form_state, $context); +} + +/** + * Implements hook_field_widget_multivalue_WIDGET_TYPE_form_alter(). + */ +function field_test_field_widget_multivalue_test_field_widget_multiple_single_value_form_alter(array &$elements, FormStateInterface $form_state, array $context) { + _field_test_alter_widget("hook_field_widget_multivalue_WIDGET_TYPE_form_alter", $elements, $form_state, $context); +} + + +/** + * Sets up alterations for widget alter tests. + * + * @see \Drupal\field\Tests\FormTest::widgetAlterTest() + */ +function _field_test_alter_widget($hook, array &$elements, FormStateInterface $form_state, array $context) { + + // Set a message if this is for the form displayed to set default value for + // the field. + if ($context['default']) { + drupal_set_message("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."; + } + } +} + /** * Implements hook_query_TAG_alter() for tag 'efq_table_prefixing_test'. * @@ -171,3 +206,14 @@ function field_test_entity_bundle_field_info_alter(&$fields, EntityTypeInterface ]); } } + +/** + * Implements hook_field_ui_preconfigured_options_alter(). + */ +function field_test_field_ui_preconfigured_options_alter(array &$options, $field_type) { + if ($field_type === 'test_field_with_preconfigured_options') { + $options['custom_options']['entity_view_display']['settings'] = [ + 'test_formatter_setting_multiple' => 'altered dummy test string', + ]; + } +}