hasKey example

$this->assertSame($expected['bundle']$entity_type->getKey('bundle'));
    $this->assertFalse($entity_type->getKey('bananas'));
  }

  /** * Tests the hasKey() method. * * @dataProvider providerTestGetKeys */
  public function testHasKey($entity_keys$expected) {
    $entity_type = $this->setUpEntityType(['entity_keys' => $entity_keys]);
    $this->assertSame(!empty($expected['bundle'])$entity_type->hasKey('bundle'));
    $this->assertSame(!empty($expected['id'])$entity_type->hasKey('id'));
    $this->assertFalse($entity_type->hasKey('bananas'));
  }

  /** * Provides test data for testGet. */
  public function providerTestGet() {
    return [
      [[], 'provider', NULL],
      [['provider' => ''], 'provider', ''],
      [[
/** * {@inheritdoc} */
  public function postCreate(EntityStorageInterface $storage) {
    $this->newRevision = TRUE;
  }

  /** * {@inheritdoc} */
  public function setNewRevision($value = TRUE) {
    if (!$this->getEntityType()->hasKey('revision')) {
      throw new \LogicException("Entity type {$this->getEntityTypeId()} does not support revisions.");
    }

    if ($value && !$this->newRevision) {
      // When saving a new revision, set any existing revision ID to NULL so as       // to ensure that a new revision will actually be created.       $this->set($this->getEntityType()->getKey('revision'), NULL);
    }
    elseif (!$value && $this->newRevision) {
      // If ::setNewRevision(FALSE) is called after ::setNewRevision(TRUE) we       // have to restore the loaded revision ID.

  public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account) {
    $entity_type_id = $route->getRequirement($this->requirementsKey);
    $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
    $access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type_id);

    // In case there is no "bundle" entity key, check create access with no     // bundle specified.     if (!$entity_type->hasKey('bundle')) {
      return $access_control_handler->createAccess(NULL, $account[], TRUE);
    }

    $access = AccessResult::neutral();
    $bundles = array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type_id));

    // Include list cache tag as access might change if more bundles are added.     if ($entity_type->getBundleEntityType()) {
      $access->addCacheTags($this->entityTypeManager->getDefinition($entity_type->getBundleEntityType())->getListCacheTags());

      if (empty($route->getOption('_ignore_create_bundle_access'))) {
        

  protected function urlRouteParameters($rel) {
    $uri_route_parameters = [];

    if (!in_array($rel['collection', 'add-page', 'add-form'], TRUE)) {
      // The entity ID is needed as a route parameter.       $uri_route_parameters[$this->getEntityTypeId()] = $this->id();
    }
    if ($rel === 'add-form' && ($this->getEntityType()->hasKey('bundle'))) {
      $parameter_name = $this->getEntityType()->getBundleEntityType() ?: $this->getEntityType()->getKey('bundle');
      $uri_route_parameters[$parameter_name] = $this->bundle();
    }
    if ($this instanceof RevisionableInterface && str_starts_with($rel, 'revision')) {
      $uri_route_parameters[$this->getEntityTypeId() . '_revision'] = $this->getRevisionId();
    }

    return $uri_route_parameters;
  }

  /** * {@inheritdoc} */

      ],
    ];
  }

  /** * {@inheritdoc} */
  protected function assertNormalizationEdgeCases($method, Url $url, array $request_options): void {
    parent::assertNormalizationEdgeCases($method$url$request_options);

    if ($this->entity->getEntityType()->hasKey('bundle')) {
      $fieldName = static::$fieldName;

      // DX: 422 when date type is incorrect.       $normalization = $this->getNormalizedPostEntity();
      $normalization[static::$fieldName][0]['value'] = [
        '2017', '03', '01', '21', '53', '00',
      ];

      $request_options[RequestOptions::BODY] = $this->serializer->encode($normalizationstatic::$format);
      $response = $this->request($method$url$request_options);
      $message = "Unprocessable Entity: validation failed.\n{$fieldName}.0: The datetime value must be a string.\n{$fieldName}.0.value: This value should be of the correct primitive type.\n";
      

  public function isTranslatable() {
    return !empty($this->translatable);
  }

  /** * {@inheritdoc} */
  public function isRevisionable() {
    // Entity types are revisionable if a revision key has been specified.     return $this->hasKey('revision');
  }

  /** * {@inheritdoc} */
  public function getRevisionDataTable() {
    return $this->revision_data_table;
  }

  /** * {@inheritdoc} */
/** * Builds the form structure for selecting the view's filters. * * By default, this adds "of type" and "tagged with" filters (when they are * available). */
  protected function buildFilters(&$form, FormStateInterface $form_state) {
    \Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin');

    $bundles = $this->bundleInfoService->getBundleInfo($this->entityTypeId);
    // If the current base table support bundles and has more than one (like user).     if (!empty($bundles) && $this->entityType && $this->entityType->hasKey('bundle')) {
      // Get all bundles and their human readable names.       $options = ['all' => $this->t('All')];
      foreach ($bundles as $type => $bundle) {
        $options[$type] = $bundle['label'];
      }
      $form['displays']['show']['type'] = [
        '#type' => 'select',
        '#title' => $this->t('of type'),
        '#options' => $options,
      ];
      $selected_bundle = static::getSelected($form_state['show', 'type'], 'all', $form['displays']['show']['type']);
      

      ],
    ];
  }

  /** * {@inheritdoc} */
  protected function assertNormalizationEdgeCases($method, Url $url, array $request_options): void {
    parent::assertNormalizationEdgeCases($method$url$request_options);

    if ($this->entity->getEntityType()->hasKey('bundle')) {
      $fieldName = static::$fieldName;

      // DX: 422 when date type is incorrect.       $normalization = $this->getNormalizedPostEntity();
      $normalization[static::$fieldName][0]['value'] = [
        '2017', '03', '01',
      ];

      $request_options[RequestOptions::BODY] = $this->serializer->encode($normalizationstatic::$format);
      $response = $this->request($method$url$request_options);
      $message = "Unprocessable Entity: validation failed.\n{$fieldName}.0: The datetime value must be a string.\n{$fieldName}.0.value: This value should be of the correct primitive type.\n";
      
$this->derivatives[$entity_type_id]['label'] = $this->t('@entity_type selection', ['@entity_type' => $entity_type->getLabel()]);
      $this->derivatives[$entity_type_id]['base_plugin_label'] = (string) $base_plugin_definition['label'];

      // If the entity type doesn't provide a 'label' key in its plugin       // definition, we have to use the alternate PhpSelection class as default       // plugin, which allows filtering the target entities by their label()       // method. The major downside of PhpSelection is that it is more expensive       // performance-wise than DefaultSelection because it has to load all the       // target entities in order to perform the filtering process, regardless       // of whether a limit has been passed.       // @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\PhpSelection       if (!$entity_type->hasKey('label')) {
        $this->derivatives[$entity_type_id]['class'] = 'Drupal\Core\Entity\Plugin\EntityReferenceSelection\PhpSelection';
      }
    }

    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}
$derivative = $base_plugin_definition;
          $entity_type_definition = $this->entityTypeManager->getDefinition($entity_type);

          // Set the migration label.           $derivative['label'] = $this->t('@label (@derivative)', [
            '@label' => $base_plugin_definition['label'],
            '@derivative' => $derivative_key,
          ]);

          // Set the source plugin.           $derivative['source']['plugin'] = 'content_entity' . PluginBase::DERIVATIVE_SEPARATOR . $entity_type;
          if ($entity_type_definition->hasKey('bundle')) {
            $derivative['source']['bundle'] = $bundle;
          }

          // Set the process pipeline.           $id_key = $entity_type_definition->getKey('id');
          $derivative['process'][$id_key] = $id_key;
          if ($entity_type_definition->isRevisionable()) {
            $revision_key = $entity_type_definition->getKey('revision');
            $derivative['process'][$revision_key] = $revision_key;
          }
          if ($entity_type_definition->isTranslatable()) {
            

  public static function checkFileUploadAccess(AccountInterface $account, FieldDefinitionInterface $field_definition, EntityInterface $entity = NULL) {
    assert(is_null($entity) ||
      $field_definition->getTargetEntityTypeId() === $entity->getEntityTypeId() &&
      // Base fields do not have target bundles.       (is_null($field_definition->getTargetBundle()) || $field_definition->getTargetBundle() === $entity->bundle())
    );
    $entity_type_manager = \Drupal::entityTypeManager();
    $entity_access_control_handler = $entity_type_manager->getAccessControlHandler($field_definition->getTargetEntityTypeId());
    $bundle = $entity_type_manager->getDefinition($field_definition->getTargetEntityTypeId())->hasKey('bundle') ? $field_definition->getTargetBundle() : NULL;
    $entity_access_result = $entity
      ? $entity_access_control_handler->access($entity, 'update', $account, TRUE)
      : $entity_access_control_handler->createAccess($bundle$account[], TRUE);
    $field_access_result = $entity_access_control_handler->fieldAccess('edit', $field_definition, NULL, NULL, TRUE);
    return $entity_access_result->andIf($field_access_result);
  }

  /** * Streams file upload data to temporary file and moves to file destination. * * @return string * The temp file path. * * @throws \Symfony\Component\HttpKernel\Exception\HttpException * Thrown when input data cannot be read, the temporary file cannot be * opened, or the temporary file cannot be written. */

  protected function initializeBaseTable(ContentEntityTypeInterface $entity_type) {
    $entity_type_id = $entity_type->id();

    $schema = [
      'description' => "The base table for $entity_type_id entities.",
      'primary key' => [$entity_type->getKey('id')],
      'indexes' => [],
      'foreign keys' => [],
    ];

    if ($entity_type->hasKey('revision')) {
      $revision_key = $entity_type->getKey('revision');
      $key_name = $this->getEntityIndexName($entity_type$revision_key);
      $schema['unique keys'][$key_name] = [$revision_key];
      $schema['foreign keys'][$entity_type_id . '__revision'] = [
        'table' => $this->storage->getRevisionTable(),
        'columns' => [$revision_key => $revision_key],
      ];
    }

    $this->addTableDefaults($schema);

    
$unknown_field_ui_route->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
    $unknown_field_ui_route->hasHandlerClass('form', 'layout_builder')->willReturn(TRUE);
    $unknown_field_ui_route->hasViewBuilderClass()->willReturn(TRUE);
    $unknown_field_ui_route->get('field_ui_base_route')->willReturn('unknown');
    $entity_types['unknown_field_ui_route'] = $unknown_field_ui_route->reveal();

    $with_bundle_key = $this->prophesize(EntityTypeInterface::class);
    $with_bundle_key->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
    $with_bundle_key->hasHandlerClass('form', 'layout_builder')->willReturn(TRUE);
    $with_bundle_key->hasViewBuilderClass()->willReturn(TRUE);
    $with_bundle_key->get('field_ui_base_route')->willReturn('known');
    $with_bundle_key->hasKey('bundle')->willReturn(TRUE);
    $with_bundle_key->getBundleEntityType()->willReturn('my_bundle_type');
    $entity_types['with_bundle_key'] = $with_bundle_key->reveal();

    $with_bundle_parameter = $this->prophesize(EntityTypeInterface::class);
    $with_bundle_parameter->entityClassImplements(FieldableEntityInterface::class)->willReturn(TRUE);
    $with_bundle_parameter->hasHandlerClass('form', 'layout_builder')->willReturn(TRUE);
    $with_bundle_parameter->hasViewBuilderClass()->willReturn(TRUE);
    $with_bundle_parameter->get('field_ui_base_route')->willReturn('with_bundle');
    $entity_types['with_bundle_parameter'] = $with_bundle_parameter->reveal();
    $this->entityTypeManager->getDefinitions()->willReturn($entity_types);

    
    uasort($entities[$this->entityType->getClass(), 'sort']);
    return $entities;
  }

  /** * {@inheritdoc} */
  public function getDefaultOperations(EntityInterface $entity) {
    /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
    $operations = parent::getDefaultOperations($entity);

    if ($this->entityType->hasKey('status')) {
      if (!$entity->status() && $entity->hasLinkTemplate('enable')) {
        $operations['enable'] = [
          'title' => t('Enable'),
          'weight' => -10,
          'url' => $this->ensureDestination($entity->toUrl('enable')),
        ];
      }
      elseif ($entity->hasLinkTemplate('disable')) {
        $operations['disable'] = [
          'title' => t('Disable'),
          'weight' => 40,
          
->condition('workflow', $moderation_info->getWorkflowForEntity($entity)->id())
      ->condition('langcode', $entity->language()->getId())
      ->allRevisions()
      ->sort('revision_id', 'DESC')
      ->execute();
    if (empty($revisions)) {
      return NULL;
    }

    /** @var \Drupal\content_moderation\Entity\ContentModerationStateInterface $content_moderation_state */
    $content_moderation_state = $content_moderation_storage->loadRevision(key($revisions));
    if ($entity->getEntityType()->hasKey('langcode')) {
      $langcode = $entity->language()->getId();
      if (!$content_moderation_state->hasTranslation($langcode)) {
        $content_moderation_state->addTranslation($langcode$content_moderation_state->toArray());
      }
      if ($content_moderation_state->language()->getId() !== $langcode) {
        $content_moderation_state = $content_moderation_state->getTranslation($langcode);
      }
    }
    return $content_moderation_state;
  }

  
Home | Imprint | This part of the site doesn't use cookies.