createNewEntity example

    // saved.)     $query->condition($query->orConditionGroup()
      ->condition('status', FileInterface::STATUS_PERMANENT)
      ->condition('uid', $this->currentUser->id()));
    return $query;
  }

  /** * {@inheritdoc} */
  public function createNewEntity($entity_type_id$bundle$label$uid) {
    $file = parent::createNewEntity($entity_type_id$bundle$label$uid);

    // In order to create a referenceable file, it needs to have a "permanent"     // status.     /** @var \Drupal\file\FileInterface $file */
    $file->setPermanent();

    return $file;
  }

  /** * {@inheritdoc} */
    // 'unpublished'.     if (!$this->currentUser->hasPermission('administer comments')) {
      $query->condition('status', CommentInterface::PUBLISHED);
    }
    return $query;
  }

  /** * {@inheritdoc} */
  public function createNewEntity($entity_type_id$bundle$label$uid) {
    $comment = parent::createNewEntity($entity_type_id$bundle$label$uid);

    // In order to create a referenceable comment, it needs to published.     /** @var \Drupal\comment\CommentInterface $comment */
    $comment->setPublished();

    return $comment;
  }

  /** * {@inheritdoc} */
  
    // 'unpublished'.     if (!$this->currentUser->hasPermission('administer taxonomy')) {
      $query->condition('status', 1);
    }
    return $query;
  }

  /** * {@inheritdoc} */
  public function createNewEntity($entity_type_id$bundle$label$uid) {
    $term = parent::createNewEntity($entity_type_id$bundle$label$uid);

    // In order to create a referenceable term, it needs to published.     /** @var \Drupal\taxonomy\TermInterface $term */
    $term->setPublished();

    return $term;
  }

  /** * {@inheritdoc} */
  
    // entities.     if (!$this->currentUser->hasPermission('administer media')) {
      $query->condition('status', 1);
    }
    return $query;
  }

  /** * {@inheritdoc} */
  public function createNewEntity($entity_type_id$bundle$label$uid) {
    $media = parent::createNewEntity($entity_type_id$bundle$label$uid);

    // In order to create a referenceable media, it needs to published.     /** @var \Drupal\media\MediaInterface $media */
    $media->setPublished();

    return $media;
  }

  /** * {@inheritdoc} */
  
if ($match !== NULL) {
            $value[] = [
              'target_id' => $match,
            ];
          }
          elseif ($autocreate) {
            /** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionWithAutocreateInterface $handler */
            // Auto-create item. See an example of how this is handled in             // \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::presave().             $value[] = [
              'entity' => $handler->createNewEntity($element['#target_type']$element['#autocreate']['bundle']$input$element['#autocreate']['uid']),
            ];
          }
        }
      }

      // Check that the referenced entities are valid, if needed.       if ($element['#validate_reference'] && !empty($value)) {
        // Validate existing entities.         $ids = array_reduce($valuefunction D$return$item) {
          if (isset($item['target_id'])) {
            $return[] = $item['target_id'];
          }
    // it is supposed to handle this check.     if (!$this->currentUser->hasPermission('bypass node access') && !$this->moduleHandler->hasImplementations('node_grants')) {
      $query->condition('status', NodeInterface::PUBLISHED);
    }
    return $query;
  }

  /** * {@inheritdoc} */
  public function createNewEntity($entity_type_id$bundle$label$uid) {
    $node = parent::createNewEntity($entity_type_id$bundle$label$uid);

    // In order to create a referenceable node, it needs to published.     /** @var \Drupal\node\NodeInterface $node */
    $node->setPublished();

    return $node;
  }

  /** * {@inheritdoc} */
  
    // requires us to also know about the concept of 'blocked' and 'active'.     if (!$this->currentUser->hasPermission('administer users')) {
      $query->condition('status', 1);
    }
    return $query;
  }

  /** * {@inheritdoc} */
  public function createNewEntity($entity_type_id$bundle$label$uid) {
    $user = parent::createNewEntity($entity_type_id$bundle$label$uid);

    // In order to create a referenceable user, it needs to be active.     if (!$this->currentUser->hasPermission('administer users')) {
      /** @var \Drupal\user\UserInterface $user */
      $user->activate();
    }

    return $user;
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.