class EdgeEntityType in Apigee Edge 8
Same name in this branch
- 8 src/Annotation/EdgeEntityType.php \Drupal\apigee_edge\Annotation\EdgeEntityType
- 8 src/Entity/EdgeEntityType.php \Drupal\apigee_edge\Entity\EdgeEntityType
Provides an implementation of an Apigee Edge entity type and its metadata.
Hierarchy
- class \Drupal\Component\Plugin\Definition\PluginDefinition implements PluginDefinitionInterface
- class \Drupal\Core\Entity\EntityType implements EntityTypeInterface uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\apigee_edge\Entity\EdgeEntityType implements EdgeEntityTypeInterface
- class \Drupal\Core\Entity\EntityType implements EntityTypeInterface uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of EdgeEntityType
1 file declares its use of EdgeEntityType
- EdgeEntityType.php in src/
Annotation/ EdgeEntityType.php
File
- src/
Entity/ EdgeEntityType.php, line 32
Namespace
Drupal\apigee_edge\EntityView source
class EdgeEntityType extends EntityType implements EdgeEntityTypeInterface {
/**
* The FQCN of the query class used for this entity.
*
* @var string
*/
protected $query_class = 'Drupal\\apigee_edge\\Entity\\Query\\Query';
/**
* Name of the config object that contains entity label overrides.
*
* @var string
*/
protected $config_with_labels;
/**
* EdgeEntityType constructor.
*
* @param array $definition
* An array of values from the annotation.
*
* @throws \Drupal\Core\Entity\Exception\EntityTypeIdLengthException
* Thrown when attempting to instantiate an entity type with too long ID.
*/
public function __construct(array $definition) {
parent::__construct($definition);
// Some default settings for our entity types.
$this->handlers += [
'view_builder' => EdgeEntityViewBuilder::class,
'list_builder' => EdgeEntityListBuilder::class,
'route_provider' => [
'html' => EdgeEntityRouteProvider::class,
],
];
// Add entity type id to the list cache tags to help easier cache
// invalidation.
$this->list_cache_tags[] = $this->id;
}
/**
* {@inheritdoc}
*/
public function getLabel() {
$label = $this
->getEntityLabelFromConfig('entity_label_singular');
return empty($label) ? parent::getSingularLabel() : $label;
}
/**
* {@inheritdoc}
*/
public function getSingularLabel() {
return $this
->getLabel();
}
/**
* {@inheritdoc}
*/
public function getPluralLabel() {
$label = $this
->getEntityLabelFromConfig('entity_label_plural');
return empty($label) ? parent::getPluralLabel() : $label;
}
/**
* {@inheritdoc}
*/
public function getCollectionLabel() {
// We do not want to display "XY entities" as default collection label
// rather "XYs".
$label = $this
->getEntityLabelFromConfig('entity_label_plural');
$label = $label ?: parent::getCollectionLabel();
return new TranslatableMarkup('@label', [
'@label' => $label,
], [], $this
->getStringTranslation());
}
/**
* Returns the config object that contains the entity labels.
*
* Config object should define values for the following keys:
* - entity_label_singular
* - entity_label_plural.
*
* @return \Drupal\Core\Config\ImmutableConfig|null
* Config object.
*
* @throws \Drupal\apigee_edge\Exception\RuntimeException
* If the provided config object does not exists.
*/
private function getConfigWithEntityLabels() : ?ImmutableConfig {
if (empty($this->config_with_labels)) {
return NULL;
}
$config = \Drupal::config($this->config_with_labels);
if ($config
->isNew()) {
throw new RuntimeException("Config object called {$this->config_with_labels} does not exists.");
}
return $config;
}
/**
* Returns entity label from config if exists.
*
* @param string $key
* The config object key. It starts with "entity_label_".
*
* @return string|null
* The entity label if the config and config key exists, null otherwise.
*/
protected function getEntityLabelFromConfig(string $key) : ?string {
$logger = \Drupal::logger('apigee_edge');
try {
$config = $this
->getConfigWithEntityLabels();
if ($config) {
$label = $config
->get($key);
if ($label === NULL) {
$logger
->warning('@class: The "@key" has not been found in @config config object for "@entity_type" entity.', [
'@class' => get_class($this),
'@entity_type' => $this->id,
'@key' => $key,
'@config' => $this->config_with_labels ?? "apigee_edge.{$this->id}_settings",
]);
}
return $label;
}
} catch (RuntimeException $exception) {
// Just catch it, do not log it, because this could generate invalid
// log entries when the module is uninstalled.
}
return NULL;
}
/**
* {@inheritdoc}
*/
public function getKeys() {
$keys = parent::getKeys();
// If id definition is missing from the entity annotation try to set it up
// automatically otherwise things gets broken, like entity reference fields.
if (!isset($keys['id'])) {
$rc = new \ReflectionClass($this
->getClass());
// SDK entities can tell their primary id property.
$method = 'idProperty';
if ($rc
->hasMethod($method)) {
$rm = $rc
->getMethod($method);
$keys['id'] = $rm
->invoke(NULL, $method);
}
}
return $keys;
}
/**
* {@inheritdoc}
*/
public function getQueryClass() : string {
return $this->query_class;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EdgeEntityType:: |
protected | property | Name of the config object that contains entity label overrides. | |
EdgeEntityType:: |
protected | property | The FQCN of the query class used for this entity. | |
EdgeEntityType:: |
public | function |
Gets the uppercase plural form of the name of the entity type. Overrides EntityType:: |
|
EdgeEntityType:: |
private | function | Returns the config object that contains the entity labels. | |
EdgeEntityType:: |
protected | function | Returns entity label from config if exists. | |
EdgeEntityType:: |
public | function |
Gets an array of entity keys. Overrides EntityType:: |
|
EdgeEntityType:: |
public | function |
Gets the human-readable name of the entity type. Overrides EntityType:: |
|
EdgeEntityType:: |
public | function |
Gets the indefinite plural form of the name of the entity type. Overrides EntityType:: |
|
EdgeEntityType:: |
public | function |
Returns the fully-qualified class name of the query class for this entity. Overrides EdgeEntityTypeInterface:: |
|
EdgeEntityType:: |
public | function |
Gets the indefinite singular form of the name of the entity type. Overrides EntityType:: |
|
EdgeEntityType:: |
public | function |
EdgeEntityType constructor. Overrides EntityType:: |
|
EntityType:: |
protected | property | Any additional properties and values. | |
EntityType:: |
protected | property | The name of the default administrative permission. | |
EntityType:: |
protected | property | The name of the entity type's base table. | |
EntityType:: |
protected | property | The name of the entity type which provides bundles. | |
EntityType:: |
protected | property | The human-readable name of the entity bundles, e.g. Vocabulary. | |
EntityType:: |
protected | property | The name of the entity type for which bundles are provided. | |
EntityType:: |
protected | property | Indicates whether this entity type is commonly used as a reference target. | |
EntityType:: |
protected | property | Entity constraint definitions. | |
EntityType:: |
protected | property | The name of the entity type's data table. | |
EntityType:: |
protected | property | An array of entity keys. | |
EntityType:: |
protected | property | The route name used by field UI to attach its management pages. | |
EntityType:: |
protected | property | The machine name of the entity type group. | |
EntityType:: |
protected | property | The human-readable name of the entity type group. | |
EntityType:: |
protected | property | An array of handlers. | |
EntityType:: |
protected | property |
The unique identifier of this entity type. Overrides PluginDefinition:: |
|
EntityType:: |
protected | property | Indicates whether the entity data is internal. | |
EntityType:: |
protected | property | The human-readable name of the type. | |
EntityType:: |
protected | property | The name of a callback that returns the label of the entity. | |
EntityType:: |
protected | property | The human-readable label for a collection of entities of the type. | |
EntityType:: |
protected | property | A definite singular/plural name of the type. | |
EntityType:: |
protected | property | The indefinite plural name of the type. | |
EntityType:: |
protected | property | The indefinite singular name of the type. | |
EntityType:: |
protected | property | Link templates using the URI template syntax. | |
EntityType:: |
protected | property | The list cache contexts for this entity type. | |
EntityType:: |
protected | property | The list cache tags for this entity type. | |
EntityType:: |
protected | property | The name of the original entity type class. | |
EntityType:: |
protected | property | The permission granularity level. | |
EntityType:: |
protected | property | Indicates if the persistent cache of field data should be used. | |
EntityType:: |
protected | property | Indicates whether the rendered output of entities should be cached. | |
EntityType:: |
protected | property | The name of the entity type's revision data table. | |
EntityType:: |
protected | property | The name of the entity type's revision table. | |
EntityType:: |
protected | property | Indicates whether the revision form fields should be added to the form. | |
EntityType:: |
protected | property | Indicates whether entities should be statically cached. | 1 |
EntityType:: |
protected | property | Indicates whether entities of this type have multilingual support. | |
EntityType:: |
protected | property | A callable that can be used to provide the entity URI. | |
EntityType:: |
public | function |
Adds a validation constraint. Overrides EntityTypeInterface:: |
|
EntityType:: |
protected | function | Checks that the provided class is compatible with the current entity type. | 2 |
EntityType:: |
public | function |
Indicates if the entity type class implements the given interface. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets any arbitrary property. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the access control class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the name of the default administrative permission. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the name of the entity's base table. Overrides EntityTypeInterface:: |
1 |
EntityType:: |
public | function |
Gets the config dependency info for this entity, if any exists. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the name of the entity type which provides bundles. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the label for the bundle. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the entity type for which this entity provides bundles. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the key that is used to store configuration dependencies. Overrides EntityTypeInterface:: |
2 |
EntityType:: |
public | function |
Gets an array of validation constraints. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the label's definite article form for use with a count of entities. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the name of the entity's data table. Overrides EntityTypeInterface:: |
1 |
EntityType:: |
public | function |
Gets the form class for a specific operation. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the machine name of the entity type group. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the human-readable name of the entity type group. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets an array of handlers. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets a specific entity key. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the callback for the label of the entity. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the link template for a given key. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the link templates using the URI template syntax. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the list class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
The list cache contexts associated with this entity type. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
The list cache tags associated with this entity type. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the lowercase form of the human-readable entity type name. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the name of the original entity type class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the permission granularity level. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the name of the entity's revision data table. Overrides EntityTypeInterface:: |
1 |
EntityType:: |
public | function |
Gets the name of the entity's revision table. Overrides EntityTypeInterface:: |
1 |
EntityType:: |
public | function |
Gets all the route provide handlers. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the storage class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets a callable that can be used to provide the entity URI. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the view builder class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if this entity type has any forms. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Determines if there is a handler for a given type. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if a given entity key exists. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if a label callback exists. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if a link template exists for a given key. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if this entity type has a list class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if this entity type has any route provider. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if this entity type has a view builder. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether this entity type is commonly used as a reference target. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether the entity data is internal. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if the persistent cache of field data should be used. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether the rendered output of entities should be cached. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether entities of this type have revision support. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether entities should be statically cached. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if the entity type is a subclass of the given class or interface. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether entities of this type have multilingual support. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets a value to an arbitrary property. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets the access control handler class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets the class. Overrides PluginDefinition:: |
|
EntityType:: |
public | function |
Sets the array of validation constraints for the FieldItemList. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets a form class for a specific operation. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets the handlers for a given type. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets the label callback. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets a single link template. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets the list class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets the storage class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets a callable to use to provide the entity URI. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the view builder class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether the revision form fields should be added to the form. Overrides EntityTypeInterface:: |
|
EntityTypeInterface:: |
constant | The maximum length of bundle name, in characters. | ||
EntityTypeInterface:: |
constant | The maximum length of ID, in characters. | ||
PluginDefinition:: |
protected | property | A fully qualified class name. | |
PluginDefinition:: |
protected | property | The plugin provider. | |
PluginDefinition:: |
public | function |
Gets the class. Overrides PluginDefinitionInterface:: |
|
PluginDefinition:: |
public | function |
Gets the plugin provider. Overrides PluginDefinitionInterface:: |
|
PluginDefinition:: |
public | function |
Gets the unique identifier of the plugin. Overrides PluginDefinitionInterface:: |
1 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |