Chris@0: t('Content types'); Chris@0: return $form; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') { Chris@0: $query = parent::buildEntityQuery($match, $match_operator); Chris@0: // Adding the 'node_access' tag is sadly insufficient for nodes: core Chris@0: // requires us to also know about the concept of 'published' and Chris@0: // 'unpublished'. We need to do that as long as there are no access control Chris@0: // modules in use on the site. As long as one access control module is there, Chris@0: // it is supposed to handle this check. Chris@0: if (!$this->currentUser->hasPermission('bypass node access') && !count($this->moduleHandler->getImplementations('node_grants'))) { Chris@0: $query->condition('status', NodeInterface::PUBLISHED); Chris@0: } Chris@0: return $query; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function createNewEntity($entity_type_id, $bundle, $label, $uid) { Chris@0: $node = parent::createNewEntity($entity_type_id, $bundle, $label, $uid); Chris@0: Chris@0: // In order to create a referenceable node, it needs to published. Chris@0: /** @var \Drupal\node\NodeInterface $node */ Chris@0: $node->setPublished(TRUE); Chris@0: Chris@0: return $node; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function validateReferenceableNewEntities(array $entities) { Chris@0: $entities = parent::validateReferenceableNewEntities($entities); Chris@0: // Mirror the conditions checked in buildEntityQuery(). Chris@0: if (!$this->currentUser->hasPermission('bypass node access') && !count($this->moduleHandler->getImplementations('node_grants'))) { Chris@0: $entities = array_filter($entities, function ($node) { Chris@0: /** @var \Drupal\node\NodeInterface $node */ Chris@0: return $node->isPublished(); Chris@0: }); Chris@0: } Chris@0: return $entities; Chris@0: } Chris@0: Chris@0: }