Commit 8ec62297 authored by catch's avatar catch
Browse files

Issue #3261241 by andypost, longwave: Remove deprecated field module functions

parent b7ab11cc
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -119,10 +119,6 @@ public function form(FieldItemListInterface $items, array &$form, FormStateInter
      'items' => $items,
      'default' => $this->isDefaultValueWidget($form_state),
    ];
    \Drupal::moduleHandler()->alterDeprecated('Deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use hook_field_widget_complete_form_alter or hook_field_widget_complete_WIDGET_TYPE_form_alter instead. See https://www.drupal.org/node/3180429.', [
      'field_widget_multivalue_form',
      'field_widget_multivalue_' . $this->getPluginId() . '_form',
    ], $elements, $form_state, $context);

    // Populate the 'array_parents' information in $form_state->get('field')
    // after the form is built, so that we catch changes in the form structure
@@ -361,7 +357,6 @@ protected function formSingleElement(FieldItemListInterface $items, $delta, arra
        'delta' => $delta,
        'default' => $this->isDefaultValueWidget($form_state),
      ];
      \Drupal::moduleHandler()->alterDeprecated('Deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use hook_field_widget_single_element_form_alter or hook_field_widget_single_element_WIDGET_TYPE_form_alter instead. See https://www.drupal.org/node/3180429.', ['field_widget_form', 'field_widget_' . $this->getPluginId() . '_form'], $element, $form_state, $context);
      \Drupal::moduleHandler()->alter(['field_widget_single_element_form', 'field_widget_single_element_' . $this->getPluginId() . '_form'], $element, $form_state, $context);
    }

+0 −155
Original line number Diff line number Diff line
@@ -160,85 +160,6 @@ function hook_field_widget_info_alter(array &$info) {
  $info['options_select']['field_types'][] = 'my_field_type';
}

/**
 * Alter forms for field widgets provided by other modules.
 *
 * This hook can only modify individual elements within a field widget and
 * cannot alter the top level (parent element) for multi-value fields. In most
 * cases, you should use hook_field_widget_multivalue_form_alter() instead and
 * loop over the elements.
 *
 * @param $element
 *   The field widget form element as constructed by
 *   \Drupal\Core\Field\WidgetBaseInterface::form().
 * @param $form_state
 *   The current state of the form.
 * @param $context
 *   An associative array containing the following key-value pairs:
 *   - form: The form structure to which widgets are being attached. This may be
 *     a full form structure, or a sub-element of a larger form.
 *   - widget: The widget plugin instance.
 *   - items: The field values, as a
 *     \Drupal\Core\Field\FieldItemListInterface object.
 *   - delta: The order of this item in the array of subelements (0, 1, 2, etc).
 *   - default: A boolean indicating whether the form is being shown as a dummy
 *     form to set default values.
 *
 * @deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use
 *   hook_field_widget_single_element_form_alter instead.
 *
 * @see https://www.drupal.org/node/3180429
 * @see \Drupal\Core\Field\WidgetBaseInterface::form()
 * @see \Drupal\Core\Field\WidgetBase::formSingleElement()
 * @see hook_field_widget_WIDGET_TYPE_form_alter()
 * @see hook_field_widget_multivalue_form_alter()
 */
function hook_field_widget_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $form_state, $context) {
  // Add a css class to widget form elements for all fields of type my_type.
  $field_definition = $context['items']->getFieldDefinition();
  if ($field_definition->getType() == 'my_type') {
    // Be sure not to overwrite existing attributes.
    $element['#attributes']['class'][] = 'my-class';
  }
}

/**
 * Alter widget forms for a specific widget provided by another module.
 *
 * Modules can implement hook_field_widget_WIDGET_TYPE_form_alter() to modify a
 * specific widget form, rather than using hook_field_widget_form_alter() and
 * checking the widget type.
 *
 * This hook can only modify individual elements within a field widget and
 * cannot alter the top level (parent element) for multi-value fields. In most
 * cases, you should use hook_field_widget_multivalue_WIDGET_TYPE_form_alter()
 * instead and loop over the elements.
 *
 * @param $element
 *   The field widget form element as constructed by
 *   \Drupal\Core\Field\WidgetBaseInterface::form().
 * @param $form_state
 *   The current state of the form.
 * @param $context
 *   An associative array. See hook_field_widget_form_alter() for the structure
 *   and content of the array.
 *
 * @deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use
 *   hook_field_widget_single_element_WIDGET_TYPE_form_alter instead.
 *
 * @see https://www.drupal.org/node/3180429
 * @see \Drupal\Core\Field\WidgetBaseInterface::form()
 * @see \Drupal\Core\Field\WidgetBase::formSingleElement()
 * @see hook_field_widget_form_alter()
 * @see hook_field_widget_multivalue_WIDGET_TYPE_form_alter()
 */
function hook_field_widget_WIDGET_TYPE_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $form_state, $context) {
  // Code here will only act on widgets of type WIDGET_TYPE.  For example,
  // hook_field_widget_mymodule_autocomplete_form_alter() will only act on
  // widgets of type 'mymodule_autocomplete'.
  $element['#autocomplete_route_name'] = 'mymodule.autocomplete_route';
}

/**
 * Alter forms for field widgets provided by other modules.
 *
@@ -373,82 +294,6 @@ function hook_field_widget_complete_WIDGET_TYPE_form_alter(&$field_widget_comple
  $field_widget_complete_form['#attributes']['class'][] = 'my-class';
}

/**
 * Alter forms for multi-value field widgets provided by other modules.
 *
 * To alter the individual elements within the widget, loop over
 * \Drupal\Core\Render\Element::children($elements).
 *
 * @param array $elements
 *   The field widget form elements as constructed by
 *   \Drupal\Core\Field\WidgetBase::formMultipleElements().
 * @param \Drupal\Core\Form\FormStateInterface $form_state
 *   The current state of the form.
 * @param array $context
 *   An associative array containing the following key-value pairs:
 *   - form: The form structure to which widgets are being attached. This may be
 *     a full form structure, or a sub-element of a larger form.
 *   - widget: The widget plugin instance.
 *   - items: The field values, as a
 *     \Drupal\Core\Field\FieldItemListInterface object.
 *   - default: A boolean indicating whether the form is being shown as a dummy
 *     form to set default values.
 *
 * @deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use
 *   hook_field_widget_complete_form_alter instead.
 *
 * @see https://www.drupal.org/node/3180429
 * @see \Drupal\Core\Field\WidgetBaseInterface::form()
 * @see \Drupal\Core\Field\WidgetBase::formMultipleElements()
 * @see hook_field_widget_multivalue_WIDGET_TYPE_form_alter()
 */
function hook_field_widget_multivalue_form_alter(array &$elements, \Drupal\Core\Form\FormStateInterface $form_state, array $context) {
  // Add a css class to widget form elements for all fields of type my_type.
  $field_definition = $context['items']->getFieldDefinition();
  if ($field_definition->getType() == 'my_type') {
    // Be sure not to overwrite existing attributes.
    $elements['#attributes']['class'][] = 'my-class';
  }
}

/**
 * Alter multi-value widget forms for a widget provided by another module.
 *
 * Modules can implement hook_field_widget_multivalue_WIDGET_TYPE_form_alter() to
 * modify a specific widget form, rather than using
 * hook_field_widget_form_alter() and checking the widget type.
 *
 * To alter the individual elements within the widget, loop over
 * \Drupal\Core\Render\Element::children($elements).
 *
 * @param array $elements
 *   The field widget form elements as constructed by
 *   \Drupal\Core\Field\WidgetBase::formMultipleElements().
 * @param \Drupal\Core\Form\FormStateInterface $form_state
 *   The current state of the form.
 * @param array $context
 *   An associative array. See hook_field_widget_multivalue_form_alter() for
 *   the structure and content of the array.
 *
 * @deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use
 *   hook_field_widget_complete_WIDGET_TYPE_form_alter instead.
 *
 * @see https://www.drupal.org/node/3180429
 * @see \Drupal\Core\Field\WidgetBaseInterface::form()
 * @see \Drupal\Core\Field\WidgetBase::formMultipleElements()
 * @see hook_field_widget_multivalue_form_alter()
 */
function hook_field_widget_multivalue_WIDGET_TYPE_form_alter(array &$elements, \Drupal\Core\Form\FormStateInterface $form_state, array $context) {
  // Code here will only act on widgets of type WIDGET_TYPE. For example,
  // hook_field_widget_multivalue_mymodule_autocomplete_form_alter() will only
  // act on widgets of type 'mymodule_autocomplete'.
  // Change the autocomplete route for each autocomplete element within the
  // multivalue widget.
  foreach (Element::children($elements) as $delta => $element) {
    $elements[$delta]['#autocomplete_route_name'] = 'mymodule.autocomplete_route';
  }
}

/**
 * @} End of "defgroup field_widget".
 */
+0 −7
Original line number Diff line number Diff line
@@ -4,13 +4,6 @@ services:
    arguments: ['@entity_type.manager']
    tags:
     - { name: event_subscriber }
  field_ui.route_enhancer:
    alias: route_enhancer.entity_bundle
    deprecated: The "%alias_id%" service is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use the "route_enhancer.entity_bundle" service instead. See https://www.drupal.org/node/3245017
    class: Drupal\Core\Entity\Enhancer\EntityBundleRouteEnhancer
    arguments: ['@entity_type.manager']
    tags:
      - { name: route_enhancer }
  access_check.field_ui.view_mode:
    class: Drupal\field_ui\Access\ViewModeAccessCheck
    arguments: ['@entity_type.manager']
+0 −17
Original line number Diff line number Diff line
<?php

namespace Drupal\field_ui\Routing;

@trigger_error('The ' . __NAMESPACE__ . '\EntityBundleRouteEnhancer is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Instead, use \Drupal\Core\Entity\Enhancer\EntityBundleRouteEnhancer. See https://www.drupal.org/node/3245017', E_USER_DEPRECATED);

use Drupal\Core\Entity\Enhancer\EntityBundleRouteEnhancer;

/**
 * Enhances Field UI routes by adding proper information about the bundle name.
 *
 * @deprecated in drupal:9.3.0 and is removed from drupal:10.0.0.
 * Use \Drupal\Core\Entity\Enhancer\EntityBundleRouteEnhancer.
 *
 * @see https://www.drupal.org/node/3245017
 */
class FieldUiRouteEnhancer extends EntityBundleRouteEnhancer {}
+0 −32
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\field_ui\Kernel;

use Drupal\KernelTests\KernelTestBase;

/**
 * Tests that the service "field_ui.route_enhancer" has been deprecated.
 *
 * @group field_ui
 * @group legacy
 */
class FieldUiRouteEnhancerTest extends KernelTestBase {

  /**
   * Modules to install.
   *
   * @var string[]
   */
  protected static $modules = ['field_ui'];

  /**
   * Tests deprecation of the "field_ui.route_enhancer" service.
   */
  public function testFieldUiRouteEnhancerDeprecation() {
    $this->expectDeprecation('The "field_ui.route_enhancer" service is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Use the "route_enhancer.entity_bundle" service instead. See https://www.drupal.org/node/3245017');
    $legacy_service = \Drupal::service('field_ui.route_enhancer');
    $new_service = \Drupal::service('route_enhancer.entity_bundle');
    $this->assertSame($new_service, $legacy_service);
  }

}
Loading