function taxonomy_update_8503

Update views to use {taxonomy_term__parent} in relationships.

File

core/modules/taxonomy/taxonomy.install, line 138

Code

function taxonomy_update_8503() {
    $config_factory = \Drupal::configFactory();
    foreach ($config_factory->listAll('views.view.') as $id) {
        $view = $config_factory->getEditable($id);
        foreach (array_keys($view->get('display')) as $display_id) {
            $changed = FALSE;
            foreach ([
                'relationships',
                'filters',
                'arguments',
            ] as $handler_type) {
                $base_path = "display.{$display_id}.display_options.{$handler_type}";
                $handlers = $view->get($base_path);
                if (!$handlers) {
                    continue;
                }
                foreach ($handlers as $handler_key => $handler_config) {
                    $table_path = "{$base_path}.{$handler_key}.table";
                    $field_path = "{$base_path}.{$handler_key}.field";
                    $table = $view->get($table_path);
                    $field = $view->get($field_path);
                    if ($table && $table === 'taxonomy_term_hierarchy' && ($field && $field === 'parent')) {
                        $view->set($table_path, 'taxonomy_term__parent');
                        $view->set($field_path, 'parent_target_id');
                        $changed = TRUE;
                    }
                }
            }
            if ($changed) {
                $view->save(TRUE);
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.