getTypeProvider example

->condition('module', $providers, 'NOT IN')
        ->execute();
      if (!empty($field_storages)) {
        $storages_to_delete = FieldStorageConfig::loadMultiple($field_storages);
      }
    }

    // Gather deleted fields from modules that are being uninstalled.     /** @var \Drupal\field\FieldStorageConfigInterface[] $deleted_storage_definitions */
    $deleted_storage_definitions = \Drupal::service('entity_field.deleted_fields_repository')->getFieldStorageDefinitions();
    foreach ($deleted_storage_definitions as $field_storage_definition) {
      if ($field_storage_definition instanceof FieldStorageConfigInterface && !in_array($field_storage_definition->getTypeProvider()$providers)) {
        $storages_to_delete[$field_storage_definition->id()] = $field_storage_definition;
      }
    }
    return $storages_to_delete;
  }

}
$this->assertNull($field->getSetting('datetime_type'));

    // Assert node and user reference fields.     $field = FieldStorageConfig::load('node.field_node_reference');
    $this->assertEquals('node', $field->getSetting('target_type'));
    $field = FieldStorageConfig::load('node.field_user_reference');
    $this->assertEquals('user', $field->getSetting('target_type'));

    // Make sure a datetime field with a todate is now a daterange type.     $field = FieldStorageConfig::load('node.field_event');
    $this->assertSame('daterange', $field->getType());
    $this->assertSame('datetime_range', $field->getTypeProvider());
    $this->assertEquals('datetime', $field->getSetting('datetime_type'));

    // Test the migration of text fields with different text processing.     // All text and text_long field bases that have only plain text instances     // should be migrated to string and string_long fields.     // All text_with_summary field bases that have only plain text instances     // should not have been migrated since there's no such thing as a     // string_with_summary field.     $this->assertEntity('node.field_text_plain', 'string', TRUE, 1);
    $this->assertEntity('node.field_text_long_plain', 'string_long', TRUE, 1);
    $this->assertNull(FieldStorageConfig::load('node.field_text_sum_plain'));

    
// Notify the field storage definition listener.     \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionCreate($this);
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    // Ensure the field is dependent on the providing module.     $this->addDependency('module', $this->getTypeProvider());
    // Ask the field type for any additional storage dependencies.     // @see \Drupal\Core\Field\FieldItemInterface::calculateStorageDependencies()     $definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($this->getType(), FALSE);
    $this->addDependencies($definition['class']::calculateStorageDependencies($this));

    // Ensure the field is dependent on the provider of the entity type.     $entity_type = \Drupal::entityTypeManager()->getDefinition($this->entity_type);
    $this->addDependency('module', $entity_type->getProvider());
    return $this;
  }

  

function hook_field_storage_config_update_forbid(\Drupal\field\FieldStorageConfigInterface $field_storage, \Drupal\field\FieldStorageConfigInterface $prior_field_storage) {
  if ($field_storage->getTypeProvider() == 'options' && $field_storage->hasData()) {
    // Forbid any update that removes allowed values with actual data.     $allowed_values = $field_storage->getSetting('allowed_values');
    $prior_allowed_values = $prior_field_storage->getSetting('allowed_values');
    $lost_keys = array_keys(array_diff_key($prior_allowed_values$allowed_values));
    if (_options_values_in_use($field_storage->getTargetEntityTypeId()$field_storage->getName()$lost_keys)) {
      throw new \Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException("A list field '{$field_storage->getName()}' with existing data cannot have its keys changed.");
    }
  }
}

/** * @} End of "defgroup field_types". */
Home | Imprint | This part of the site doesn't use cookies.