Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295161

Sub local task not associate to the good local task

$
0
0

Hi,

I create local task dynamically with datas from database. Each task has the same route name. I use parameters.

admin_content.footer_column:
  path: '/admin/content/footer/{column}'
  ...

Each local task has some sub local tasks, also generated dynamically so with the same route name with parameters.

admin_content.footer_column_section:
  path: '/admin/content/footer/{column}/section/{section}'
  ...

My problem is that when I select a local task, I always have the same sub local tasks, the ones generated for the last local task. Yet I have used the parent_id to attach my sub local tasks to the good local task like describe in the documentation (https://www.drupal.org/node/2122253).

Here is the sample of my script for generate the local tasks :

public function getDerivativeDefinitions($base_plugin_definition)
{
    $columns = db_select('footer_column', 'c')
        ->fields('c', array('id', 'default_name'))
        ->execute()
        ->fetchAll();

    $first = true;
    foreach($columns as $column) {
        $this->derivatives[$column->id] = $base_plugin_definition;
        $this->derivatives[$column->id]['title'] = $column->default_name;

        if($first) {
            $this->derivatives[$column->id]['route_name'] = 'admin_content.footer';
        } else {
            $this->derivatives[$column->id]['route_name'] = 'admin_content.footer_column';
            $this->derivatives[$column->id]['route_parameters'] = array(
                'column' => $column->id
            );
        }

        $this->derivatives[$column->id]['weight'] = $column->id;

        $first = false;
    }

    return $this->derivatives;
}

And the one for generate the sub local tasks :

public function getDerivativeDefinitions($base_plugin_definition)
{
    $columns = db_select('footer_column', 'c')
        ->fields('c', array('id'))
        ->execute()
        ->fetchCol();

    $sections = array();
    $sections[0] = 'Hors Section';
    $tree = \Drupal::entityManager()->getStorage('taxonomy_term')->loadTree('arborescence', 0, 1);

    foreach($tree as $entry) {
        $sections[$entry->tid] = $entry->name;
    }

    $i = 0;
    foreach($columns as $column) {
        foreach ($sections as $tid => $name) {
            $this->derivatives[$i] = $base_plugin_definition;

            if ($tid == 0) { // Tab par défaut
                if ($i == 0) {
                    $this->derivatives[$i]['route_name'] = 'admin_content.footer';
                } else {
                    $this->derivatives[$i]['route_name'] = 'admin_content.footer_column';
                    $this->derivatives[$i]['route_parameters'] = array(
                        'column' => $column,
                    );
                }
            } else {
                $this->derivatives[$i]['route_name'] = 'admin_content.footer_column_section';
                $this->derivatives[$i]['route_parameters'] = array(
                    'column' => $column,
                    'section' => $tid
                );
            }

            $this->derivatives[$i]['title'] = $name;
            $this->derivatives[$i]['parent_id'] = 'admin_content.footer_column:' . $column;
            $this->derivatives[$i]['weight'] = $i;

            $i++;
        }
    }

    return $this->derivatives;
}

Perhaps I dont build the local task correctly but I dont understand how to do.

Best regards,

Xavier


Viewing all articles
Browse latest Browse all 295161

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>