entityManager = $entity_manager; $this->languageManager = $language_manager; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, $plugin_id, $plugin_definition, $container->get('entity.manager'), $container->get('language_manager') ); } /** * {@inheritdoc} */ public function usesGroupBy() { return FALSE; } /** * {@inheritdoc} */ public function defineOptions() { $options = parent::defineOptions(); $options['destination'] = [ 'default' => TRUE, ]; return $options; } /** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); $form['destination'] = [ '#type' => 'checkbox', '#title' => $this->t('Include destination'), '#description' => $this->t('Include a destination parameter in the link to return the user to the original view upon completing the link action.'), '#default_value' => $this->options['destination'], ]; } /** * {@inheritdoc} */ public function render(ResultRow $values) { $entity = $this->getEntityTranslation($this->getEntity($values), $values); $operations = $this->entityManager->getListBuilder($entity->getEntityTypeId())->getOperations($entity); if ($this->options['destination']) { foreach ($operations as &$operation) { if (!isset($operation['query'])) { $operation['query'] = []; } $operation['query'] += $this->getDestinationArray(); } } $build = [ '#type' => 'operations', '#links' => $operations, ]; return $build; } /** * {@inheritdoc} */ public function query() { // We purposefully do not call parent::query() because we do not want the // default query behavior for Views fields. Instead, let the entity // translation renderer provide the correct query behavior. if ($this->languageManager->isMultilingual()) { $this->getEntityTranslationRenderer()->query($this->query, $this->relationship); } } /** * {@inheritdoc} */ public function getEntityTypeId() { return $this->getEntityType(); } /** * {@inheritdoc} */ protected function getEntityManager() { return $this->entityManager; } /** * {@inheritdoc} */ protected function getLanguageManager() { return $this->languageManager; } /** * {@inheritdoc} */ protected function getView() { return $this->view; } /** * {@inheritdoc} */ public function clickSortable() { return FALSE; } }