You are here

function cck_select_other_views_data_alter in CCK Select Other 8

Same name and namespace in other branches
  1. 6 views/cck_select_other.views.inc \cck_select_other_views_data_alter()
  2. 7.2 views/cck_select_other.views.inc \cck_select_other_views_data_alter()
  3. 7 views/cck_select_other.views.inc \cck_select_other_views_data_alter()

Implements of hook_views_data_alter().

File

./cck_select_other.views.inc, line 10
Contains \cck_select_other_views_data_alter().

Code

function cck_select_other_views_data_alter(array &$data) {
  try {

    // Get all the displays because Drupal.
    $displays = \Drupal::entityTypeManager()
      ->getStorage('entity_form_display')
      ->loadMultiple();

    /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $display */
    foreach ($displays as $display) {

      // Get all the components on the display, which will allow to load the
      // renderer for each given field name and thus get the widget plugin id.
      foreach ($display
        ->getComponents() as $field_name => $configuration) {
        $widget = $display
          ->getRenderer($field_name);
        if (isset($widget)) {
          $widget_id = $widget
            ->getPluginId();
          if ($widget_id === 'cck_select_other') {
            $table = $display
              ->getTargetEntityTypeId() . '__' . $field_name;
            $field = $field_name . '_value';
            $data[$table][$field]['filter']['id'] = 'select_other';
          }
        }
      }
    }
  } catch (\Exception $e) {

    // @todo catch this.
    throw $e;
  }
}