5 * Contains \Drupal\linkit\Plugin\Linkit\Matcher\NodeMatcher.
8 namespace Drupal\linkit\Plugin\Linkit\Matcher;
10 use Drupal\Core\Form\FormStateInterface;
15 * target_entity = "node",
16 * label = @Translation("Content"),
20 class NodeMatcher extends EntityMatcher {
25 public function getSummary() {
26 $summery = parent::getSummary();
28 $summery[] = $this->t('Include unpublished: @include_unpublished', [
29 '@include_unpublished' => $this->configuration['include_unpublished'] ? $this->t('Yes') : $this->t('No'),
38 public function defaultConfiguration() {
39 return parent::defaultConfiguration() + [
40 'include_unpublished' => FALSE,
47 public function calculateDependencies() {
48 return parent::calculateDependencies() + [
56 public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
57 $form = parent::buildConfigurationForm($form, $form_state);
59 $form['include_unpublished'] = [
60 '#title' => t('Include unpublished nodes'),
61 '#type' => 'checkbox',
62 '#default_value' => $this->configuration['include_unpublished'],
63 '#description' => t('In order to see unpublished nodes, the requesting user must also have permissions to do so.'),
72 public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
73 parent::submitConfigurationForm($form, $form_state);
75 $this->configuration['include_unpublished'] = $form_state->getValue('include_unpublished');
81 protected function buildEntityQuery($match) {
82 $query = parent::buildEntityQuery($match);
84 $no_access = !$this->currentUser->hasPermission('bypass node access') && !count($this->moduleHandler->getImplementations('node_grants'));
85 if ($this->configuration['include_unpublished'] !== TRUE || $no_access) {
86 $query->condition('status', NODE_PUBLISHED);