class RdfMapping
Same name in other branches
- 8.9.x core/modules/rdf/src/Entity/RdfMapping.php \Drupal\rdf\Entity\RdfMapping
- 8.9.x core/modules/rdf/src/Plugin/migrate/source/d7/RdfMapping.php \Drupal\rdf\Plugin\migrate\source\d7\RdfMapping
Config entity for working with RDF mappings.
Plugin annotation
@ConfigEntityType(
id = "rdf_mapping",
label = @Translation("RDF mapping"),
label_singular = @Translation("RDF mapping item"),
label_plural = @Translation("RDF mappings items"),
label_count = @PluralTranslation(
singular = "@count RDF mapping item",
plural = "@count RDF mapping items",
),
config_prefix = "mapping",
entity_keys = {
"id" = "id"
},
admin_permission = "administer site configuration",
config_export = {
"id",
"targetEntityType",
"bundle",
"types",
"fieldMappings",
}
)
Hierarchy
- class \Drupal\Core\Entity\EntityBase implements \Drupal\Core\Entity\EntityInterface uses \Drupal\Core\Cache\RefinableCacheableDependencyTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait
- class \Drupal\Core\Config\Entity\ConfigEntityBase extends \Drupal\Core\Entity\EntityBase implements \Drupal\Core\Config\Entity\ConfigEntityInterface uses \Drupal\Core\Plugin\PluginDependencyTrait, \Drupal\Core\Entity\SynchronizableEntityTrait
- class \Drupal\rdf\Entity\RdfMapping extends \Drupal\Core\Config\Entity\ConfigEntityBase implements \Drupal\rdf\RdfMappingInterface
- class \Drupal\Core\Config\Entity\ConfigEntityBase extends \Drupal\Core\Entity\EntityBase implements \Drupal\Core\Config\Entity\ConfigEntityInterface uses \Drupal\Core\Plugin\PluginDependencyTrait, \Drupal\Core\Entity\SynchronizableEntityTrait
Expanded class hierarchy of RdfMapping
4 files declare their use of RdfMapping
- rdf.module in core/
modules/ rdf/ rdf.module - Enables semantically enriched output for Drupal sites in the form of RDFa.
- RdfMappingConfigEntityUnitTest.php in core/
modules/ rdf/ tests/ src/ Unit/ RdfMappingConfigEntityUnitTest.php - RdfMappingResourceTestBase.php in core/
modules/ rdf/ tests/ src/ Functional/ Rest/ RdfMappingResourceTestBase.php - RdfMappingTest.php in core/
modules/ rdf/ tests/ src/ Functional/ Jsonapi/ RdfMappingTest.php
File
-
core/
modules/ rdf/ src/ Entity/ RdfMapping.php, line 35
Namespace
Drupal\rdf\EntityView source
class RdfMapping extends ConfigEntityBase implements RdfMappingInterface {
/**
* Unique ID for the config entity.
*
* @var string
*/
protected $id;
/**
* Entity type to be mapped.
*
* @var string
*/
protected $targetEntityType;
/**
* Bundle to be mapped.
*
* @var string
*/
protected $bundle;
/**
* The RDF type mapping for this bundle.
*
* @var array
*/
protected $types = [];
/**
* The mappings for fields on this bundle.
*
* @var array
*/
protected $fieldMappings = [];
/**
* {@inheritdoc}
*/
public function getPreparedBundleMapping() {
return [
'types' => $this->types,
];
}
/**
* {@inheritdoc}
*/
public function getBundleMapping() {
if (!empty($this->types)) {
return [
'types' => $this->types,
];
}
return [];
}
/**
* {@inheritdoc}
*/
public function setBundleMapping(array $mapping) {
if (isset($mapping['types'])) {
$this->types = $mapping['types'];
}
return $this;
}
/**
* {@inheritdoc}
*/
public function getPreparedFieldMapping($field_name) {
$field_mapping = [
'properties' => NULL,
'datatype' => NULL,
'datatype_callback' => NULL,
'mapping_type' => NULL,
];
if (isset($this->fieldMappings[$field_name])) {
$field_mapping = array_merge($field_mapping, $this->fieldMappings[$field_name]);
}
return empty($field_mapping['properties']) ? [] : $field_mapping;
}
/**
* {@inheritdoc}
*/
public function getFieldMapping($field_name) {
if (isset($this->fieldMappings[$field_name])) {
return $this->fieldMappings[$field_name];
}
return [];
}
/**
* {@inheritdoc}
*/
public function setFieldMapping($field_name, array $mapping = []) {
$this->fieldMappings[$field_name] = $mapping;
return $this;
}
/**
* {@inheritdoc}
*/
public function id() {
return $this->targetEntityType . '.' . $this->bundle;
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
parent::calculateDependencies();
// Create dependency on the bundle.
$entity_type = \Drupal::entityTypeManager()->getDefinition($this->targetEntityType);
$this->addDependency('module', $entity_type->getProvider());
$bundle_config_dependency = $entity_type->getBundleConfigDependency($this->bundle);
$this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
return $this;
}
/**
* {@inheritdoc}
*/
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
if (\Drupal::entityTypeManager()->hasHandler($this->targetEntityType, 'view_builder')) {
\Drupal::entityTypeManager()->getViewBuilder($this->targetEntityType)
->resetCache();
}
}
}
Members
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.