Score:0

Read view row entities and create a node for each entity

in flag

I have a view that looks like in the following screenshot.

screenshot

I am creating a custom action to publish selected comments and create a node for each comment. The custom action code is the following.

class publishtraction extends ViewsBulkOperationsActionBase {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function execute($entity = NULL, $view = NULL) {
    // Publish the selected comment.
    $entity->setPublished(TRUE)->save();
    
    // Create a node for the selected comment.
    
    // Don't return anything for a default completion message; otherwise return translatable markup.
    return $this->t('Some result');
  }

  /**
   * {@inheritdoc}
   */
  public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
    if ($object->getEntityType() === 'node') {
      $access = $object->access('update', $account, TRUE)
        ->andIf($object->status->access('edit', $account, TRUE));
      return $return_as_object ? $access : $access->isAllowed();
    }

    // Other entity types may have different access methods and properties.
    return TRUE;
  }

}

My custom action is publishing/unpublishing the comments correctly. However, as next step, I want to read the multiselect field and the selected view row entities values to show them with var_dump().

How can I achieve that?

in flag
Is your goal to display the row entities without a full page refresh - i.e. via some ajax method?
Jiah avatar
in flag
My goal is to publish the selected items and create a node on the selected content type. I want that to happen at the same action. Without a page refresh would work.
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.