Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
|
@ -5,7 +5,6 @@
|
|||
* Enables semantically enriched output for Drupal sites in the form of RDFa.
|
||||
*/
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Template\Attribute;
|
||||
|
||||
|
@ -39,7 +38,7 @@ function rdf_help($route_name, RouteMatchInterface $route_match) {
|
|||
* themes are coded to be RDFa compatible.
|
||||
*/
|
||||
/**
|
||||
* Returns the RDF mapping object associated to a bundle.
|
||||
* Returns the RDF mapping object associated with a bundle.
|
||||
*
|
||||
* The function reads the rdf_mapping object from the current configuration,
|
||||
* or returns a ready-to-use empty one if no configuration entry exists yet for
|
||||
|
@ -247,6 +246,9 @@ function rdf_comment_storage_load($comments) {
|
|||
*/
|
||||
function rdf_theme() {
|
||||
return array(
|
||||
'rdf_wrapper' => array(
|
||||
'variables' => array('attributes' => array(), 'content' => NULL),
|
||||
),
|
||||
'rdf_metadata' => array(
|
||||
'variables' => array('metadata' => array()),
|
||||
),
|
||||
|
@ -267,6 +269,27 @@ function rdf_preprocess_html(&$variables) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_HOOK() for UID field templates.
|
||||
*/
|
||||
function rdf_preprocess_field__node__uid(&$variables) {
|
||||
_rdf_set_field_rel_attribute($variables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the field property attribute into a rel attribute.
|
||||
*/
|
||||
function _rdf_set_field_rel_attribute(&$variables) {
|
||||
// Swap the regular field property attribute and use the rel attribute
|
||||
// instead so that it plays well with the RDFa markup when only a link is
|
||||
// present in the field output, for example in the case of the uid field.
|
||||
if (!empty($variables['attributes']['property'])) {
|
||||
$variables['attributes']['rel'] = $variables['attributes']['property'];
|
||||
unset($variables['attributes']['property']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_HOOK() for node templates.
|
||||
*/
|
||||
|
@ -294,12 +317,6 @@ function rdf_preprocess_node(&$variables) {
|
|||
);
|
||||
}
|
||||
|
||||
// Adds RDFa markup for the relation between the node and its author.
|
||||
$author_mapping = $mapping->getPreparedFieldMapping('uid');
|
||||
if (!empty($author_mapping['properties']) && $variables['display_submitted']) {
|
||||
$variables['author_attributes']['rel'] = $author_mapping['properties'];
|
||||
}
|
||||
|
||||
// Adds RDFa markup for the date.
|
||||
$created_mapping = $mapping->getPreparedFieldMapping('created');
|
||||
if (!empty($created_mapping) && $variables['display_submitted']) {
|
||||
|
@ -416,7 +433,7 @@ function rdf_preprocess_username(&$variables) {
|
|||
// Long usernames are truncated by template_preprocess_username(). Store the
|
||||
// full name in the content attribute so it can be extracted in RDFa.
|
||||
if ($variables['truncated']) {
|
||||
$variables['attributes']['content'] = SafeMarkup::checkPlain($variables['name_raw']);
|
||||
$variables['attributes']['content'] = $variables['name_raw'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -440,11 +457,19 @@ function rdf_preprocess_comment(&$variables) {
|
|||
// Adds RDFa markup for the relation between the comment and its author.
|
||||
$author_mapping = $mapping->getPreparedFieldMapping('uid');
|
||||
if (!empty($author_mapping)) {
|
||||
$author_attributes = array('rel' => $author_mapping['properties']);
|
||||
// Wraps the author variable and the submitted variable which are both
|
||||
// available in comment.html.twig.
|
||||
$variables['author'] = SafeMarkup::set('<span ' . new Attribute($author_attributes) . '>' . $variables['author'] . '</span>');
|
||||
$variables['submitted'] = SafeMarkup::set('<span ' . new Attribute($author_attributes) . '>' . $variables['submitted'] . '</span>');
|
||||
$author_attributes = ['rel' => $author_mapping['properties']];
|
||||
// Wraps the 'author' and 'submitted' variables which are both available in
|
||||
// comment.html.twig.
|
||||
$variables['author'] = [
|
||||
'#theme' => 'rdf_wrapper',
|
||||
'#content' => $variables['author'],
|
||||
'#attributes' => $author_attributes,
|
||||
];
|
||||
$variables['submitted'] = [
|
||||
'#theme' => 'rdf_wrapper',
|
||||
'#content' => $variables['submitted'],
|
||||
'#attributes' => $author_attributes,
|
||||
];
|
||||
}
|
||||
// Adds RDFa markup for the date of the comment.
|
||||
$created_mapping = $mapping->getPreparedFieldMapping('created');
|
||||
|
@ -457,11 +482,12 @@ function rdf_preprocess_comment(&$variables) {
|
|||
'#theme' => 'rdf_metadata',
|
||||
'#metadata' => array($date_attributes),
|
||||
);
|
||||
$created_metadata_markup = drupal_render($rdf_metadata);
|
||||
// Appends the markup to the created variable and the submitted variable
|
||||
// which are both available in comment.html.twig.
|
||||
$variables['created'] = SafeMarkup::set(SafeMarkup::escape($variables['created']) . $created_metadata_markup);
|
||||
$variables['submitted'] = SafeMarkup::set($variables['submitted'] . $created_metadata_markup);
|
||||
// Ensure the original variable is represented as a render array.
|
||||
$created = !is_array($variables['created']) ? ['#markup' => $variables['created']] : $variables['created'];
|
||||
$submitted = !is_array($variables['submitted']) ? ['#markup' => $variables['submitted']] : $variables['submitted'];
|
||||
// Make render array and RDF metadata available in comment.html.twig.
|
||||
$variables['created'] = [$created, $rdf_metadata];
|
||||
$variables['submitted'] = [$submitted, $rdf_metadata];
|
||||
}
|
||||
$title_mapping = $mapping->getPreparedFieldMapping('subject');
|
||||
if (!empty($title_mapping)) {
|
||||
|
|
|
@ -34,7 +34,7 @@ class CommonDataConverter {
|
|||
* Returns the ISO 8601 timestamp.
|
||||
*/
|
||||
public static function dateIso8601Value($data) {
|
||||
return date_iso8601($data['value']);
|
||||
return \Drupal::service('date.formatter')->format($data['value'], 'custom', 'c', 'UTC');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -141,15 +141,13 @@ class RdfMapping extends ConfigEntityBase implements RdfMappingInterface {
|
|||
*/
|
||||
public function calculateDependencies() {
|
||||
parent::calculateDependencies();
|
||||
|
||||
// Create dependency on the bundle.
|
||||
$entity_type = \Drupal::entityManager()->getDefinition($this->targetEntityType);
|
||||
$this->addDependency('module', $entity_type->getProvider());
|
||||
$bundle_entity_type_id = $entity_type->getBundleEntityType();
|
||||
if ($bundle_entity_type_id != 'bundle') {
|
||||
// If the target entity type uses entities to manage its bundles then
|
||||
// depend on the bundle entity.
|
||||
$bundle_entity = \Drupal::entityManager()->getStorage($bundle_entity_type_id)->load($this->bundle);
|
||||
$this->addDependency('config', $bundle_entity->getConfigDependencyName());
|
||||
}
|
||||
$bundle_config_dependency = $entity_type->getBundleConfigDependency($this->bundle);
|
||||
$this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
|
||||
|
||||
return $this->dependencies;
|
||||
}
|
||||
|
||||
|
|
|
@ -144,6 +144,24 @@ class CommentAttributesTest extends CommentTestBase {
|
|||
$this->assertTrue($graph->hasProperty($this->nodeUri, 'http://rdfs.org/sioc/ns#num_replies', $expected_value), 'Number of comments found in RDF output of full node view mode (sioc:num_replies).');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests comment author link markup has not been broken by RDF.
|
||||
*/
|
||||
public function testCommentRdfAuthorMarkup() {
|
||||
// Post a comment as a registered user.
|
||||
$this->saveComment($this->node->id(), $this->webUser->id());
|
||||
|
||||
// Give the user access to view user profiles so the profile link shows up.
|
||||
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access user profiles']);
|
||||
$this->drupalLogin($this->webUser);
|
||||
|
||||
// Ensure that the author link still works properly after the author output
|
||||
// is modified by the RDF module.
|
||||
$this->drupalGet('node/' . $this->node->id());
|
||||
$this->assertLink($this->webUser->getUsername());
|
||||
$this->assertLinkByHref('user/' . $this->webUser->id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if RDFa markup for meta information is present in comments.
|
||||
*
|
||||
|
@ -264,14 +282,14 @@ class CommentAttributesTest extends CommentTestBase {
|
|||
// Comment date.
|
||||
$expected_value = array(
|
||||
'type' => 'literal',
|
||||
'value' => date('c', $comment->getCreatedTime()),
|
||||
'value' => format_date($comment->getCreatedTime(), 'custom', 'c', 'UTC'),
|
||||
'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
|
||||
);
|
||||
$this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Comment date found in RDF output (dc:date).');
|
||||
// Comment date.
|
||||
$expected_value = array(
|
||||
'type' => 'literal',
|
||||
'value' => date('c', $comment->getCreatedTime()),
|
||||
'value' => format_date($comment->getCreatedTime(), 'custom', 'c', 'UTC'),
|
||||
'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
|
||||
);
|
||||
$this->assertTrue($graph->hasProperty($comment_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Comment date found in RDF output (dc:created).');
|
||||
|
|
|
@ -24,7 +24,7 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
|||
$this->assertFormatterRdfa(array('type' => 'number_integer'), 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is not created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field-item") and @content]');
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__items") and @content]');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,8 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
|||
* Tests the integer formatter with settings.
|
||||
*/
|
||||
public function testIntegerFormatterWithSettings() {
|
||||
\Drupal::service('theme_handler')->install(['classy']);
|
||||
$this->config('system.theme')->set('default', 'classy')->save();
|
||||
$this->fieldType = 'integer';
|
||||
$formatter = array(
|
||||
'type' => 'number_integer',
|
||||
|
@ -50,7 +52,7 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
|||
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field-item") and @content=:testValue]', array(':testValue' => $testValue));
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(':testValue' => $testValue));
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
|
@ -65,7 +67,7 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
|||
$this->assertFormatterRdfa(array('type' => 'number_unformatted'), 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is not created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field-item") and @content]');
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__items") and @content]');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
|
@ -73,6 +75,8 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
|||
* Tests the float formatter with settings.
|
||||
*/
|
||||
public function testFloatFormatterWithSettings() {
|
||||
\Drupal::service('theme_handler')->install(['classy']);
|
||||
$this->config('system.theme')->set('default', 'classy')->save();
|
||||
$this->fieldType = 'float';
|
||||
$formatter = array(
|
||||
'type' => 'number_decimal',
|
||||
|
@ -92,7 +96,7 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
|||
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field-item") and @content=:testValue]', array(':testValue' => $testValue));
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(':testValue' => $testValue));
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
|
@ -113,7 +117,7 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
|||
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is not created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field-item") and @content]');
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__items") and @content]');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
|
@ -121,6 +125,8 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
|||
* Tests the float formatter with a scale. Scale is exercised.
|
||||
*/
|
||||
public function testFloatFormatterWithScaleExercised() {
|
||||
\Drupal::service('theme_handler')->install(['classy']);
|
||||
$this->config('system.theme')->set('default', 'classy')->save();
|
||||
$this->fieldType = 'float';
|
||||
$formatter = array(
|
||||
'type' => 'number_decimal',
|
||||
|
@ -134,7 +140,7 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
|||
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field-item") and @content=:testValue]', array(':testValue' => $testValue));
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(':testValue' => $testValue));
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
|
@ -149,7 +155,7 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
|||
$this->assertFormatterRdfa(array('type' => 'number_decimal'), 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is not created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field-item") and @content]');
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__items") and @content]');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
|
@ -157,6 +163,8 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
|||
* Tests the decimal formatter with settings.
|
||||
*/
|
||||
public function testDecimalFormatterWithSettings() {
|
||||
\Drupal::service('theme_handler')->install(['classy']);
|
||||
$this->config('system.theme')->set('default', 'classy')->save();
|
||||
$this->fieldType = 'decimal';
|
||||
$formatter = array(
|
||||
'type' => 'number_decimal',
|
||||
|
@ -176,7 +184,7 @@ class NumberFieldRdfaTest extends FieldRdfaTestBase {
|
|||
$this->assertFormatterRdfa($formatter, 'http://schema.org/baseSalary', array('value' => $testValue));
|
||||
|
||||
// Test that the content attribute is created.
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field-item") and @content=:testValue]', array(':testValue' => $testValue));
|
||||
$result = $this->xpathContent($this->getRawContent(), '//div[contains(@class, "field__item") and @content=:testValue]', array(':testValue' => $testValue));
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
|
|
|
@ -107,6 +107,10 @@ class StandardProfileTest extends WebTestBase {
|
|||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Use Classy theme for testing markup output.
|
||||
\Drupal::service('theme_handler')->install(['classy']);
|
||||
$this->config('system.theme')->set('default', 'classy')->save();
|
||||
|
||||
$this->baseUri = \Drupal::url('<front>', [], ['absolute' => TRUE]);
|
||||
|
||||
// Create two test users.
|
||||
|
@ -356,7 +360,7 @@ class StandardProfileTest extends WebTestBase {
|
|||
// Created date.
|
||||
$expected_value = array(
|
||||
'type' => 'literal',
|
||||
'value' => date_iso8601($node->get('created')->value),
|
||||
'value' => format_date($node->get('created')->value, 'custom', 'c', 'UTC'),
|
||||
'lang' => 'en',
|
||||
);
|
||||
$this->assertTrue($graph->hasProperty($uri, 'http://schema.org/dateCreated', $expected_value), "$message_prefix created date was found (schema:dateCreated) in teaser.");
|
||||
|
@ -445,7 +449,7 @@ class StandardProfileTest extends WebTestBase {
|
|||
// Comment created date.
|
||||
$expected_value = array(
|
||||
'type' => 'literal',
|
||||
'value' => date_iso8601($this->articleComment->get('created')->value),
|
||||
'value' => format_date($this->articleComment->get('created')->value, 'custom', 'c', 'UTC'),
|
||||
'lang' => 'en',
|
||||
);
|
||||
$this->assertTrue($graph->hasProperty($this->articleCommentUri, 'http://schema.org/dateCreated', $expected_value), 'Article comment created date was found (schema:dateCreated).');
|
||||
|
|
13
core/modules/rdf/templates/rdf-wrapper.html.twig
Normal file
13
core/modules/rdf/templates/rdf-wrapper.html.twig
Normal file
|
@ -0,0 +1,13 @@
|
|||
{#
|
||||
/**
|
||||
* @file
|
||||
* Default theme implementation for wrapping content with RDF attributes.
|
||||
*
|
||||
* Available variables:
|
||||
* - content: The content being wrapped with RDF attributes.
|
||||
* - attributes: HTML attributes, including RDF attributes for wrapper element.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
#}
|
||||
<span{{ attributes }}>{{ content }}</span>
|
|
@ -80,7 +80,7 @@ class RdfMappingConfigEntityUnitTest extends UnitTestCase {
|
|||
$values = array('targetEntityType' => $target_entity_type_id);
|
||||
$target_entity_type->expects($this->any())
|
||||
->method('getBundleEntityType')
|
||||
->will($this->returnValue('bundle'));
|
||||
->will($this->returnValue(NULL));
|
||||
|
||||
$this->entityManager->expects($this->at(0))
|
||||
->method('getDefinition')
|
||||
|
@ -109,16 +109,9 @@ class RdfMappingConfigEntityUnitTest extends UnitTestCase {
|
|||
$bundle_id = $this->randomMachineName(10);
|
||||
$values = array('targetEntityType' => $target_entity_type_id , 'bundle' => $bundle_id);
|
||||
|
||||
$bundle_entity_type_id = $this->randomMachineName(17);
|
||||
$bundle_entity = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityInterface');
|
||||
$bundle_entity
|
||||
->expects($this->once())
|
||||
->method('getConfigDependencyName')
|
||||
->will($this->returnValue('test_module.type.' . $bundle_id));
|
||||
|
||||
$target_entity_type->expects($this->any())
|
||||
->method('getBundleEntityType')
|
||||
->will($this->returnValue($bundle_entity_type_id));
|
||||
->method('getBundleConfigDependency')
|
||||
->will($this->returnValue(array('type' => 'config', 'name' => 'test_module.type.' . $bundle_id)));
|
||||
|
||||
$this->entityManager->expects($this->at(0))
|
||||
->method('getDefinition')
|
||||
|
@ -129,17 +122,6 @@ class RdfMappingConfigEntityUnitTest extends UnitTestCase {
|
|||
->with($this->entityTypeId)
|
||||
->will($this->returnValue($this->entityType));
|
||||
|
||||
$storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
|
||||
$storage->expects($this->once())
|
||||
->method('load')
|
||||
->with($bundle_id)
|
||||
->will($this->returnValue($bundle_entity));
|
||||
|
||||
$this->entityManager->expects($this->once())
|
||||
->method('getStorage')
|
||||
->with($bundle_entity_type_id)
|
||||
->will($this->returnValue($storage));
|
||||
|
||||
$entity = new RdfMapping($values, $this->entityTypeId);
|
||||
$dependencies = $entity->calculateDependencies();
|
||||
$this->assertContains('test_module.type.' . $bundle_id, $dependencies['config']);
|
||||
|
|
Reference in a new issue