RdfMapping.php in Drupal 8
File
core/modules/rdf/src/Entity/RdfMapping.php
View source
<?php
namespace Drupal\rdf\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\rdf\RdfMappingInterface;
class RdfMapping extends ConfigEntityBase implements RdfMappingInterface {
protected $id;
protected $targetEntityType;
protected $bundle;
protected $types = [];
protected $fieldMappings = [];
public function getPreparedBundleMapping() {
return [
'types' => $this->types,
];
}
public function getBundleMapping() {
if (!empty($this->types)) {
return [
'types' => $this->types,
];
}
return [];
}
public function setBundleMapping(array $mapping) {
if (isset($mapping['types'])) {
$this->types = $mapping['types'];
}
return $this;
}
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;
}
public function getFieldMapping($field_name) {
if (isset($this->fieldMappings[$field_name])) {
return $this->fieldMappings[$field_name];
}
return [];
}
public function setFieldMapping($field_name, array $mapping = []) {
$this->fieldMappings[$field_name] = $mapping;
return $this;
}
public function id() {
return $this->targetEntityType . '.' . $this->bundle;
}
public function calculateDependencies() {
parent::calculateDependencies();
$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;
}
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();
}
}
}
Classes
Name |
Description |
RdfMapping |
Config entity for working with RDF mappings. |