Score:2

Grab State variable value from View grid - Drupal 9

in flag

I have a drupal view that has a multiselect field at the top. Based on the grid row selection and multiselect field value, specific actions are carried out on the grid rows. It's all based out of VBO module. View looks like below:

enter image description here

The multiselect field is the list of node title of a specific content type named "level2". I grabbed the "level2" node title and created that multiselect with the below code:

// Query nodes
    $storage = Drupal::getContainer()->get('entity_type.manager')->getStorage('node');
    $nids = $storage->getQuery();

    // Gather published Level2 nodes and sort by title
    $nids = $nids->condition('type', 'level2')
      ->condition('status', 1)
      ->sort('level2_title')
      ->execute();

    // If there are no nodes, move on
    if (!$nids) {
      return FALSE;
    }

    // Start building out the options for our select list
    $options = [];
    $nodes = $storage->loadMultiple($nids);

    // Push titles into select list
    foreach ($nodes as $node) {
      $options[$node->id()] = $node->getTitle();
    }

    $form['exposed_input']['ka_types'] = [
      '#type' => 'select',
      '#options' => $options,
      '#multiple' => TRUE,
      '#title' => 'Publish to Key Activities :',
    ];
    array_unshift($form['#submit'], 'mymod_form_submit');
  }

When performing a specific activity with the multiselect field, on the action file i read the value of the multiselect as:

$ka_selected = \Drupal::state()->get('ka_types');

However, I am unable to read the same field from the grid. doing dpm($entity) and dpm($node) does not show this field at all in the grid. Any help on how to read this field value from the view grid?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.