Move all files to 2017/
This commit is contained in:
parent
ac7370f67f
commit
2875863330
15717 changed files with 0 additions and 0 deletions
36
2017/web/core/modules/rdf/src/CommonDataConverter.php
Normal file
36
2017/web/core/modules/rdf/src/CommonDataConverter.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\rdf;
|
||||
|
||||
/**
|
||||
* Contains methods for common data conversions.
|
||||
*/
|
||||
class CommonDataConverter {
|
||||
|
||||
/**
|
||||
* Provides a passthrough to place unformatted values in content attributes.
|
||||
*
|
||||
* @param mixed $data
|
||||
* The data to be placed in the content attribute.
|
||||
*
|
||||
* @return mixed
|
||||
* Returns the data.
|
||||
*/
|
||||
public static function rawValue($data) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a date entity field array into an ISO 8601 timestamp string.
|
||||
*
|
||||
* @param array $data
|
||||
* The array containing the 'value' element.
|
||||
*
|
||||
* @return string
|
||||
* Returns the ISO 8601 timestamp.
|
||||
*/
|
||||
public static function dateIso8601Value($data) {
|
||||
return \Drupal::service('date.formatter')->format($data['value'], 'custom', 'c', 'UTC');
|
||||
}
|
||||
|
||||
}
|
167
2017/web/core/modules/rdf/src/Entity/RdfMapping.php
Normal file
167
2017/web/core/modules/rdf/src/Entity/RdfMapping.php
Normal file
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\rdf\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\rdf\RdfMappingInterface;
|
||||
|
||||
/**
|
||||
* Config entity for working with RDF mappings.
|
||||
*
|
||||
* @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",
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
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::entityManager()->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::entityManager()->hasHandler($this->targetEntityType, 'view_builder')) {
|
||||
\Drupal::entityManager()->getViewBuilder($this->targetEntityType)->resetCache();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\rdf\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 7 rdf source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_rdf_mapping",
|
||||
* source_module = "rdf"
|
||||
* )
|
||||
*/
|
||||
class RdfMapping extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('rdf_mapping', 'r')->fields('r');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$field_mappings = [];
|
||||
foreach (unserialize($row->getSourceProperty('mapping')) as $field => $mapping) {
|
||||
if ($field === 'rdftype') {
|
||||
$row->setSourceProperty('types', $mapping);
|
||||
}
|
||||
else {
|
||||
$field_mappings[$field] = $mapping;
|
||||
}
|
||||
}
|
||||
$row->setSourceProperty('fieldMappings', $field_mappings);
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return [
|
||||
'type' => $this->t('The name of the entity type a mapping applies to (node, user, comment, etc.'),
|
||||
'bundle' => $this->t('The name of the bundle a mapping applies to.'),
|
||||
'mapping' => $this->t('The serialized mapping of the bundle type and fields to RDF terms.'),
|
||||
'types' => $this->t('RDF types.'),
|
||||
'fieldMappings' => $this->t('RDF field mappings.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
return [
|
||||
'type' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
'bundle' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
107
2017/web/core/modules/rdf/src/RdfMappingInterface.php
Normal file
107
2017/web/core/modules/rdf/src/RdfMappingInterface.php
Normal file
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\rdf;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface defining an RDF mapping entity.
|
||||
*/
|
||||
interface RdfMappingInterface extends ConfigEntityInterface {
|
||||
|
||||
/**
|
||||
* Gets the mapping for the bundle-level data.
|
||||
*
|
||||
* The prepared bundle mapping should be used when outputting data in RDF
|
||||
* serializations such as RDFa. In the prepared mapping, the mapping
|
||||
* configuration's CURIE arrays are processed into CURIE strings suitable for
|
||||
* output.
|
||||
*
|
||||
* @return array
|
||||
* The bundle mapping.
|
||||
*/
|
||||
public function getPreparedBundleMapping();
|
||||
|
||||
/**
|
||||
* Gets the mapping config for the bundle-level data.
|
||||
*
|
||||
* This function returns the bundle mapping as stored in config, which may
|
||||
* contain CURIE arrays. If the mapping is needed for output in a
|
||||
* serialization format, such as RDFa, then getPreparedBundleMapping() should
|
||||
* be used instead.
|
||||
*
|
||||
* @return array
|
||||
* The bundle mapping, or an empty array if there is no mapping.
|
||||
*/
|
||||
public function getBundleMapping();
|
||||
|
||||
/**
|
||||
* Sets the mapping config for the bundle-level data.
|
||||
*
|
||||
* This only sets bundle-level mappings, such as the RDF type. Mappings for
|
||||
* a bundle's fields should be handled with setFieldMapping.
|
||||
*
|
||||
* Example usage:
|
||||
* -Map the 'article' bundle to 'sioc:Post'.
|
||||
* @code
|
||||
* rdf_get_mapping('node', 'article')
|
||||
* ->setBundleMapping(array(
|
||||
* 'types' => array('sioc:Post'),
|
||||
* ))
|
||||
* ->save();
|
||||
* @endcode
|
||||
*
|
||||
* @param array $mapping
|
||||
* The bundle mapping.
|
||||
*
|
||||
* @return \Drupal\rdf\Entity\RdfMapping
|
||||
* The RdfMapping object.
|
||||
*/
|
||||
public function setBundleMapping(array $mapping);
|
||||
|
||||
/**
|
||||
* Gets the prepared mapping for a field.
|
||||
*
|
||||
* The prepared field mapping should be used when outputting data in RDF
|
||||
* serializations such as RDFa. In the prepared mapping, the mapping
|
||||
* configuration's CURIE arrays are processed into CURIE strings suitable for
|
||||
* output.
|
||||
*
|
||||
* @param string $field_name
|
||||
* The name of the field.
|
||||
*
|
||||
* @return array
|
||||
* The prepared field mapping, or an empty array if there is no mapping.
|
||||
*/
|
||||
public function getPreparedFieldMapping($field_name);
|
||||
|
||||
/**
|
||||
* Gets the mapping config for a field.
|
||||
*
|
||||
* This function returns the field mapping as stored in config, which may
|
||||
* contain CURIE arrays. If the mapping is needed for output in a
|
||||
* serialization format, such as RDFa, then getPreparedFieldMapping() should
|
||||
* be used instead.
|
||||
*
|
||||
* @param string $field_name
|
||||
* The name of the field.
|
||||
*
|
||||
* @return array
|
||||
* The field mapping config array, or an empty array if there is no mapping.
|
||||
*/
|
||||
public function getFieldMapping($field_name);
|
||||
|
||||
/**
|
||||
* Sets the mapping config for a field.
|
||||
*
|
||||
* @param string $field_name
|
||||
* The name of the field.
|
||||
* @param array $mapping
|
||||
* The field mapping.
|
||||
*
|
||||
* @return \Drupal\rdf\Entity\RdfMapping
|
||||
* The RdfMapping object.
|
||||
*/
|
||||
public function setFieldMapping($field_name, array $mapping = []);
|
||||
|
||||
}
|
30
2017/web/core/modules/rdf/src/SchemaOrgDataConverter.php
Normal file
30
2017/web/core/modules/rdf/src/SchemaOrgDataConverter.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\rdf;
|
||||
|
||||
class SchemaOrgDataConverter {
|
||||
|
||||
/**
|
||||
* Converts an interaction count to a string with the interaction type.
|
||||
*
|
||||
* Schema.org defines a number of different interaction types.
|
||||
*
|
||||
* @param int $count
|
||||
* The interaction count.
|
||||
* @param array $arguments
|
||||
* An array of arguments defined in the mapping.
|
||||
* Expected keys are:
|
||||
* - interaction_type: The string to use for the type of interaction
|
||||
* (e.g. UserComments).
|
||||
*
|
||||
* @return string
|
||||
* The formatted string.
|
||||
*
|
||||
* @see http://schema.org/UserInteraction
|
||||
*/
|
||||
public static function interactionCount($count, $arguments) {
|
||||
$interaction_type = $arguments['interaction_type'];
|
||||
return "$interaction_type:$count";
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue