/**
  * Prepares an entity that defines a field definition.
  *
  * @param bool $custom_invoke_all
  *   (optional) Whether the test will set up its own
  *   ModuleHandlerInterface::invokeAll() implementation. Defaults to FALSE.
  * @param string $field_definition_id
  *   (optional) The ID to use for the field definition. Defaults to 'id'.
  * @param array $entity_keys
  *   (optional) An array of entity keys for the mocked entity type. Defaults
  *   to an empty array.
  *
  * @return \Drupal\Core\Field\BaseFieldDefinition|\Prophecy\Prophecy\ProphecyInterface
  *   A field definition object.
  */
 protected function setUpEntityWithFieldDefinition($custom_invoke_all = FALSE, $field_definition_id = 'id', $entity_keys = array())
 {
     $field_type_manager = $this->prophesize(FieldTypePluginManagerInterface::class);
     $field_type_manager->getDefaultStorageSettings('boolean')->willReturn([]);
     $field_type_manager->getDefaultFieldSettings('boolean')->willReturn([]);
     $this->container->get('plugin.manager.field.field_type')->willReturn($field_type_manager->reveal());
     $string_translation = $this->prophesize(TranslationInterface::class);
     $this->container->get('string_translation')->willReturn($string_translation->reveal());
     $entity_class = EntityManagerTestEntity::class;
     $field_definition = $this->prophesize()->willImplement(FieldDefinitionInterface::class)->willImplement(FieldStorageDefinitionInterface::class);
     $entity_class::$baseFieldDefinitions = array($field_definition_id => $field_definition->reveal());
     $entity_class::$bundleFieldDefinitions = array();
     if (!$custom_invoke_all) {
         $this->moduleHandler->getImplementations(Argument::cetera())->willReturn([]);
     }
     // Mock the base field definition override.
     $override_entity_type = $this->prophesize(EntityTypeInterface::class);
     $this->entityType = $this->prophesize(EntityTypeInterface::class);
     $this->setUpEntityManager(array('test_entity_type' => $this->entityType, 'base_field_override' => $override_entity_type));
     $override_entity_type->getClass()->willReturn($entity_class);
     $override_entity_type->getHandlerClass('storage')->willReturn(TestConfigEntityStorage::class);
     $this->entityType->getClass()->willReturn($entity_class);
     $this->entityType->getKeys()->willReturn($entity_keys + ['default_langcode' => 'default_langcode']);
     $this->entityType->isSubclassOf(FieldableEntityInterface::class)->willReturn(TRUE);
     $this->entityType->isTranslatable()->willReturn(FALSE);
     $this->entityType->getProvider()->willReturn('the_provider');
     $this->entityType->id()->willReturn('the_entity_id');
     return $field_definition->reveal();
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function buildConfigurationForm(array $form, FormStateInterface $form_state)
 {
     $tokens = ['@entity' => Unicode::strtolower($this->entityTypeLabel()), '@entities' => Unicode::strtolower($this->entityTypeLabelPlural())];
     $form['update_existing'] = ['#type' => 'radios', '#title' => $this->t('Update existing @entities', $tokens), '#description' => $this->t('Existing @entities will be determined using mappings that are <strong>unique</strong>.', $tokens), '#options' => [static::SKIP_EXISTING => $this->t('Do not update existing @entities', $tokens), static::REPLACE_EXISTING => $this->t('Replace existing @entities', $tokens), static::UPDATE_EXISTING => $this->t('Update existing @entities', $tokens)], '#default_value' => $this->configuration['update_existing']];
     $times = [static::EXPIRE_NEVER, 3600, 10800, 21600, 43200, 86400, 259200, 604800, 2592000, 2592000 * 3, 2592000 * 6, 31536000];
     $period = array_map([$this, 'formatExpire'], array_combine($times, $times));
     $form['expire'] = ['#type' => 'select', '#title' => $this->t('Expire @entities', $tokens), '#options' => $period, '#description' => $this->t('Select after how much time @entities should be deleted.', $tokens), '#default_value' => $this->configuration['expire']];
     if ($this->entityType->isSubclassOf('Drupal\\user\\EntityOwnerInterface')) {
         $form['owner_id'] = ['#type' => 'entity_autocomplete', '#title' => $this->t('Owner'), '#description' => $this->t('Select the owner of the entities to be created. Leave blank for %anonymous.', ['%anonymous' => \Drupal::config('user.settings')->get('anonymous')]), '#target_type' => 'user', '#default_value' => User::load($this->configuration['owner_id'])];
     }
     $form['advanced'] = ['#title' => $this->t('Advanced settings'), '#type' => 'details', '#collapsed' => TRUE, '#collapsible' => TRUE, '#weight' => 10];
     if ($this->entityType->isSubclassOf('Drupal\\user\\EntityOwnerInterface')) {
         $form['advanced']['authorize'] = ['#type' => 'checkbox', '#title' => $this->t('Authorize'), '#description' => $this->t('Check that the author has permission to create the @entity.', $tokens), '#default_value' => $this->configuration['authorize'], '#parents' => ['processor_configuration', 'authorize']];
     }
     $form['advanced']['skip_hash_check'] = ['#type' => 'checkbox', '#title' => $this->t('Force update'), '#description' => $this->t('Forces the update of items even if the feed did not change.'), '#default_value' => $this->configuration['skip_hash_check'], '#parents' => ['processor_configuration', 'skip_hash_check'], '#states' => ['visible' => ['input[name="processor_configuration[update_existing]"]' => ['value' => static::UPDATE_EXISTING]]]];
     return $form;
 }
 /**
  * Gets the type of the ID key for a given entity type.
  *
  * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  *   An entity type.
  *
  * @return string|null
  *   The type of the ID key for a given entity type, or NULL if the entity
  *   type does not support fields.
  */
 protected function getEntityTypeIdKeyType(EntityTypeInterface $entity_type)
 {
     if (!$entity_type->isSubclassOf(FieldableEntityInterface::class)) {
         return NULL;
     }
     $field_storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($entity_type->id());
     return $field_storage_definitions[$entity_type->getKey('id')]->getType();
 }
 /**
  * Checks whether the entity type supports modification time natively.
  *
  * @return bool
  *   TRUE if metadata is natively supported, FALSE otherwise.
  */
 protected function hasChangedTime()
 {
     return $this->entityType->isSubclassOf('Drupal\\Core\\Entity\\EntityChangedInterface') && $this->checkFieldStorageDefinitionTranslatability('changed');
 }
 /**
  * Expands the bundle information with descriptions, if known.
  *
  * @param array $bundles
  *   An array of bundle information.
  * @param \Drupal\Core\Entity\EntityTypeInterface $bundle_entity_type
  *   The ID of the bundle entity type.
  *
  * @return array
  *   The expanded array of bundle information.
  */
 protected function loadBundleDescriptions(array $bundles, EntityTypeInterface $bundle_entity_type)
 {
     if (!$bundle_entity_type->isSubclassOf('\\Drupal\\Core\\Entity\\EntityDescriptionInterface')) {
         return $bundles;
     }
     $bundle_names = array_keys($bundles);
     $storage = $this->entityTypeManager->getStorage($bundle_entity_type->id());
     /** @var \Drupal\Core\Entity\EntityDescriptionInterface[] $bundle_entities */
     $bundle_entities = $storage->loadMultiple($bundle_names);
     foreach ($bundles as $bundle_name => &$bundle_info) {
         if (isset($bundle_entities[$bundle_name])) {
             $bundle_info['description'] = $bundle_entities[$bundle_name]->getDescription();
         }
     }
     return $bundles;
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 public function isApplicable(EntityTypeInterface $entity_type)
 {
     return $entity_type->isSubclassOf(FileInterface::class);
 }