diff --git a/core/MAINTAINERS.txt b/core/MAINTAINERS.txt index 5cd6080..dcec5e1 100644 --- a/core/MAINTAINERS.txt +++ b/core/MAINTAINERS.txt @@ -255,9 +255,6 @@ Help module Image module - Nathan Haug 'quicksketch' http://drupal.org/user/35821 -JSON-LD module -- Lin Clark 'linclark' http://drupal.org/user/396253 - Locale module - Gábor Hojtsy 'Gábor Hojtsy' http://drupal.org/user/4166 diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 5ba15c9..33f2581 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -1085,7 +1085,7 @@ function hook_field_attach_purge(\Drupal\Core\Entity\EntityInterface $entity, $f * $display_options argument and the view_mode element is set to '_custom'. * See field_view_field() for more information on what its $display_options * argument contains. - * - language: The language code used for rendering. + * - langcode: The language code used for rendering. */ function hook_field_attach_view_alter(&$output, $context) { // Append RDF term mappings on displayed taxonomy links. diff --git a/core/modules/field/field.module b/core/modules/field/field.module index db31d77..13fb22c 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -866,6 +866,7 @@ function field_view_field(EntityInterface $entity, $field_name, $display_options 'entity' => $entity, 'view_mode' => $view_mode, 'display_options' => $display_options, + 'langcode' => $display_langcode, ); drupal_alter('field_attach_view', $result, $context); diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 2e91a31..e9517c0 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -611,7 +611,7 @@ public function buildGroupByForm(&$form, &$form_state) { public function submitGroupByForm(&$form, &$form_state) { parent::submitGroupByForm($form, $form_state); - $item =& $form_state['handler']->options; + $item = &$form_state['handler']->options; // Add settings for "field API" fields. $item['group_column'] = $form_state['values']['options']['group_column']; diff --git a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php index 0933641..39d9594 100644 --- a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php @@ -99,6 +99,7 @@ function testFieldViewField() { $setting = $display['settings']['test_formatter_setting_multiple']; $this->assertNoText($this->label, 'Label was not displayed.'); $this->assertText('field_test_field_attach_view_alter', 'Alter fired, display passed.'); + $this->assertText('field language is ' . LANGUAGE_NOT_SPECIFIED, 'Language is placed onto the context.'); $array = array(); foreach ($this->values as $delta => $value) { $array[] = $delta . ':' . $value['value']; diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module index c7e3b1c..15b3ea5 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -193,6 +193,10 @@ function field_test_field_attach_view_alter(&$output, $context) { if (!empty($context['display_options']['settings']['alter'])) { $output['test_field'][] = array('#markup' => 'field_test_field_attach_view_alter'); } + + if (isset($output['test_field'])) { + $output['test_field'][] = array('#markup' => 'field language is ' . $context['langcode']); + } } /** diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index af1330e..fbd0297 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -978,9 +978,11 @@ function forum_preprocess_block(&$variables) { } /** - * Preprocesses variables for forums.tpl.php. + * Prepares variables for forums templates. * - * @param $variables + * Default template: forums.html.twig. + * + * @param array $variables * An array containing the following elements: * - forums: An array of all forum objects to display for the given taxonomy * term ID. If tid = 0 then all the top-level forums are displayed. @@ -994,23 +996,32 @@ function forum_preprocess_block(&$variables) { * - 3: Posts with the most comments first. * - 4: Posts with the least comments first. * - forum_per_page: The maximum number of topics to display per page. - * - * @see forums.tpl.php */ function template_preprocess_forums(&$variables) { if ($variables['forums_defined'] = count($variables['forums']) || count($variables['parents'])) { if (!empty($variables['forums'])) { - $variables['forums'] = theme('forum_list', $variables); + $variables['forums'] = array( + '#theme' => 'forum_list', + '#forums' => $variables['forums'], + '#parents' => $variables['parents'], + '#tid' => $variables['tid'], + ); } else { - $variables['forums'] = ''; + $variables['forums'] = array(); } if ($variables['tid'] && array_search($variables['tid'], config('forum.settings')->get('containers')) === FALSE) { - $variables['topics'] = theme('forum_topic_list', $variables); + $variables['topics'] = array( + '#theme' => 'forum_topic_list', + '#tid' => $variables['tid'], + '#topics' => $variables['topics'], + '#sortby' => $variables['sortby'], + '#forum_per_page' => $variables['forum_per_page'], + ); } else { - $variables['topics'] = ''; + $variables['topics'] = array(); } // Provide separate template suggestions based on what's being output. Topic id is also accounted for. @@ -1031,24 +1042,23 @@ function template_preprocess_forums(&$variables) { } else { - $variables['forums'] = ''; - $variables['topics'] = ''; + $variables['forums'] = array(); + $variables['topics'] = array(); } } /** - * Preprocesses variables for forum-list.tpl.php. + * Prepares variables for forum list templates. * - * @param $variables + * Default template: forum-list.html.twig. + * + * @param array $variables * An array containing the following elements: * - forums: An array of all forum objects to display for the given taxonomy * term ID. If tid = 0 then all the top-level forums are displayed. * - parents: An array of taxonomy term objects that are ancestors of the * current term ID. * - tid: Taxonomy term ID of the current forum. - * - * @see forum-list.tpl.php - * @see theme_forum_list() */ function template_preprocess_forum_list(&$variables) { global $user; @@ -1080,22 +1090,26 @@ function template_preprocess_forum_list(&$variables) { } $variables['forums'][$id]->last_reply = theme('forum_submitted', array('topic' => $forum->last_post)); } - // Give meaning to $tid for themers. $tid actually stands for term id. + + $variables['pager'] = array( + '#theme' => 'pager', + ); + + // Give meaning to $tid for themers. $tid actually stands for term ID. $variables['forum_id'] = $variables['tid']; unset($variables['tid']); } /** - * Preprocesses variables for forum-topic-list.tpl.php. + * Prepares variables for forum topic list templates. * - * @param $variables + * Default template: forum-topic-list.html.twig. + * + * @param array $variables * An array containing the following elements: * - tid: Taxonomy term ID of the current forum. * - topics: An array of all the topics in the current forum. * - forum_per_page: The maximum number of topics to display per page. - * - * @see forum-topic-list.tpl.php - * @see theme_forum_topic_list() */ function template_preprocess_forum_topic_list(&$variables) { global $forum_topic_list_header; @@ -1112,7 +1126,14 @@ function template_preprocess_forum_topic_list(&$variables) { if (!empty($variables['topics'])) { $row = 0; foreach ($variables['topics'] as $id => $topic) { - $variables['topics'][$id]->icon = theme('forum_icon', array('new_posts' => $topic->new, 'num_posts' => $topic->comment_count, 'comment_mode' => $topic->comment_mode, 'sticky' => $topic->sticky, 'first_new' => $topic->first_new)); + $variables['topics'][$id]->icon = array( + '#theme' => 'forum_icon', + '#new_posts' => $topic->new, + '#num_posts' => $topic->comment_count, + '#comment_mode' => $topic->comment_mode, + '#sticky' => $topic->sticky, + '#first_new' => $topic->first_new, + ); $variables['topics'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even'; $row++; @@ -1149,13 +1170,17 @@ function template_preprocess_forum_topic_list(&$variables) { $variables['topic_id'] = $variables['tid']; unset($variables['tid']); - $variables['pager'] = theme('pager'); + $variables['pager'] = array( + '#theme' => 'pager', + ); } /** - * Preprocesses variables for forum-icon.tpl.php. + * Prepares variables for forum icon templates. + * + * Default template: forum-icon.html.twig. * - * @param $variables + * @param array $variables * An array containing the following elements: * - new_posts: Indicates whether or not the topic contains new posts. * - num_posts: The total number of posts in all topics. @@ -1163,44 +1188,43 @@ function template_preprocess_forum_topic_list(&$variables) { * or hidden. * - sticky: Indicates whether the topic is sticky. * - first_new: Indicates whether this is the first topic with new posts. - * - * @see forum-icon.tpl.php - * @see theme_forum_icon() */ function template_preprocess_forum_icon(&$variables) { $variables['hot_threshold'] = config('forum.settings')->get('topics.hot_threshold'); + $variables['attributes']['class'][] = 'icon'; if ($variables['num_posts'] > $variables['hot_threshold']) { - $variables['icon_class'] = $variables['new_posts'] ? 'hot-new' : 'hot'; + $variables['attributes']['class'][] = $variables['new_posts'] ? 'hot-new' : 'hot'; $variables['icon_title'] = $variables['new_posts'] ? t('Hot topic, new comments') : t('Hot topic'); } else { - $variables['icon_class'] = $variables['new_posts'] ? 'new' : 'default'; + $variables['attributes']['class'][] = $variables['new_posts'] ? 'new' : 'default'; $variables['icon_title'] = $variables['new_posts'] ? t('New comments') : t('Normal topic'); } if ($variables['comment_mode'] == COMMENT_NODE_CLOSED || $variables['comment_mode'] == COMMENT_NODE_HIDDEN) { - $variables['icon_class'] = 'closed'; + $variables['attributes']['class'][] = 'closed'; $variables['icon_title'] = t('Closed topic'); } if ($variables['sticky'] == 1) { - $variables['icon_class'] = 'sticky'; + $variables['attributes']['class'][] = 'sticky'; $variables['icon_title'] = t('Sticky topic'); } + + $variables['attributes']['title'] = $variables['icon_title']; } /** - * Preprocesses variables for forum-submitted.tpl.php. + * Prepares variables for forum submission information templates. * * The submission information will be displayed in the forum list and topic * list. * - * @param $variables + * Default template: forum-submitted.html.twig. + * + * @param array $variables * An array containing the following elements: * - topic: The topic object. - * - * @see forum-submitted.tpl.php - * @see theme_forum_submitted() */ function template_preprocess_forum_submitted(&$variables) { $variables['author'] = isset($variables['topic']->uid) ? theme('username', array('account' => $variables['topic'])) : ''; diff --git a/core/modules/forum/templates/forum-icon.html.twig b/core/modules/forum/templates/forum-icon.html.twig new file mode 100644 index 0000000..3a73355 --- /dev/null +++ b/core/modules/forum/templates/forum-icon.html.twig @@ -0,0 +1,26 @@ +{# +/** + * @file + * Default theme implementation to display a status icon for a forum post. + * + * Available variables: + * - attributes: HTML attributes to be applied to the wrapper element. + * - class: HTML classes that determine which icon to display. May be one of + * 'hot', 'hot-new', 'new', 'default', 'closed', or 'sticky'. + * - title: Text alternative for the forum icon. + * - icon_title: Text alternative for the forum icon, same as above. + * - new_posts: '1' when this topic contains new posts, otherwise '0'. + * - first_new: '1' when this is the first topic with new posts, otherwise '0'. + * + * @see template_preprocess() + * @see template_preprocess_forum_icon() + * + * @ingroup themeable + */ +#} +
+ {% if first_new -%} + + {%- endif %} + {{ icon_title }} +
diff --git a/core/modules/forum/templates/forum-icon.tpl.php b/core/modules/forum/templates/forum-icon.tpl.php deleted file mode 100644 index 8b70eb3..0000000 --- a/core/modules/forum/templates/forum-icon.tpl.php +++ /dev/null @@ -1,26 +0,0 @@ - -
- - - - - - -
diff --git a/core/modules/forum/templates/forum-list.html.twig b/core/modules/forum/templates/forum-list.html.twig new file mode 100644 index 0000000..fd55a77 --- /dev/null +++ b/core/modules/forum/templates/forum-list.html.twig @@ -0,0 +1,82 @@ +{# +/** + * @file + * Default theme implementation to display a list of forums and containers. + * + * Available variables: + * - forums: A collection of forums and containers to display. It is keyed to + * the numeric IDs of all child forums and containers. Each forum in forums + * contains: + * - is_container: A flag indicating if the forum can contain other + * forums. Otherwise, the forum can only contain topics. + * - depth: How deep the forum is in the current hierarchy. + * - zebra: 'even' or 'odd', used for row class. + * - icon_class: 'default' or 'new', used for forum icon class. + * - icon_title: Text alternative for the forum icon. + * - name: The name of the forum. + * - link: The URL to link to this forum. + * - description: The description field for the forum, containing: + * - value: The descriptive text for the forum. + * - new_topics: A flag indicating if the forum contains unread posts. + * - new_url: A URL to the forum's unread posts. + * - new_text: Text for the above URL, which tells how many new posts. + * - old_topics: A count of posts that have already been read. + * - num_posts: The total number of posts in the forum. + * - last_reply: Text representing the last time a forum was posted or + * commented in. + * - forum_id: Forum ID for the current forum. Parent to all items within the + * forums array. + * + * @see template_preprocess() + * @see template_preprocess_forum_list() + * + * @ingroup themeable + */ +#} + + + + + + + + + + + {% for child_id, forum in forums %} + + + {% if forum.is_container == false %} + + + + {% endif %} + + {% endfor %} + +
{{ 'Forum'|t }}{{ 'Topics'|t }}{{ 'Posts'|t }}{{ 'Last post'|t }}
+ {# + Enclose the contents of this cell with X divs, where X is the + depth this forum resides at. This will allow us to use CSS + left-margin for indenting. + #} + {% for i in 1..forum.depth if forum.depth > 0 %}
{% endfor %} +
+ {{ forum.icon_title }} +
+ + {% if forum.description.value %} +
{{ forum.description.value }}
+ {% endif %} + {% for i in 1..forum.depth if forum.depth > 0 %}
{% endfor %} +
+ {{ forum.num_topics }} + {% if forum.new_topics == true %} +
+ {{ forum.new_text }} + {% endif %} +
{{ forum.num_posts }}{{ forum.last_reply }}
diff --git a/core/modules/forum/templates/forum-list.tpl.php b/core/modules/forum/templates/forum-list.tpl.php deleted file mode 100644 index da8a12d..0000000 --- a/core/modules/forum/templates/forum-list.tpl.php +++ /dev/null @@ -1,77 +0,0 @@ -is_container: TRUE if the forum can contain other forums. FALSE - * if the forum can contain only topics. - * - $forum->depth: How deep the forum is in the current hierarchy. - * - $forum->zebra: 'even' or 'odd' string used for row class. - * - $forum->icon_class: 'default' or 'new' string used for forum icon class. - * - $forum->icon_title: Text alternative for the forum icon. - * - $forum->name: The name of the forum. - * - $forum->link: The URL to link to this forum. - * - $forum->description: The description of this forum. - * - $forum->new_topics: TRUE if the forum contains unread posts. - * - $forum->new_url: A URL to the forum's unread posts. - * - $forum->new_text: Text for the above URL, which tells how many new posts. - * - $forum->old_topics: A count of posts that have already been read. - * - $forum->num_posts: The total number of posts in the forum. - * - $forum->last_reply: Text representing the last time a forum was posted or - * commented in. - * - $forum_id: Forum ID for the current forum. Parent to all items within the - * $forums array. - * - * @see template_preprocess_forum_list() - * @see theme_forum_list() - * - * @ingroup themeable - */ -?> - - - - - - - - - - - $forum): ?> - - - is_container): ?> - - - - - - - -
is_container ? 'colspan="4" class="container"' : 'class="forum"'; ?>> - - ', $forum->depth); ?> -
- icon_title; ?> -
- - description->value): ?> -
description->value; ?>
- - ', $forum->depth); ?> -
- num_topics ?> - new_topics): ?> -
- new_text; ?> - -
num_posts ?>last_reply ?>
diff --git a/core/modules/forum/templates/forum-submitted.html.twig b/core/modules/forum/templates/forum-submitted.html.twig new file mode 100644 index 0000000..ad059dc --- /dev/null +++ b/core/modules/forum/templates/forum-submitted.html.twig @@ -0,0 +1,24 @@ +{# +/** + * @file + * Default theme implementation for a forum post submission string. + * + * The submission string indicates when and by whom a topic was submitted. + * + * Available variables: + * - author: The author of the post. + * - time: How long ago the post was created. + * - topic: An object with the raw data of the post. Potentially unsafe. Be + * sure to clean this data before printing. + * + * @see template_preprocess() + * @see template_preprocess_forum_submitted() + * + * @ingroup themeable + */ +#} +{% if time %} + {{ 'By !author @time ago'|t({'@time': time, '!author': author}) }} +{% else %} + {{ 'n/a'|t }} +{% endif %} diff --git a/core/modules/forum/templates/forum-submitted.tpl.php b/core/modules/forum/templates/forum-submitted.tpl.php deleted file mode 100644 index 18fea8f..0000000 --- a/core/modules/forum/templates/forum-submitted.tpl.php +++ /dev/null @@ -1,30 +0,0 @@ - - - - $time, - '!author' => $author, - )); ?> - - - - diff --git a/core/modules/forum/templates/forum-topic-list.html.twig b/core/modules/forum/templates/forum-topic-list.html.twig new file mode 100644 index 0000000..32727ee --- /dev/null +++ b/core/modules/forum/templates/forum-topic-list.html.twig @@ -0,0 +1,69 @@ +{# +/** + * @file + * Default theme implementation to display a list of forum topics. + * + * Available variables: + * - header: The table header. This is pre-generated with click-sorting + * information. If you need to change this, see + * template_preprocess_forum_topic_list(). + * - pager: The pager to display beneath the table. + * - topics: A collection of topics to be displayed. Each topic in topics + * contains: + * - icon: The icon to display. + * - moved: A flag to indicate whether the topic has been moved to another + * forum. + * - title: The title of the topic. Safe to output. + * - message: If the topic has been moved, this contains an explanation and a + * link. + * - zebra: 'even' or 'odd', used for row class. + * - comment_count: The number of replies on this topic. + * - new_replies: A flag to indicate whether there are unread comments. + * - new_url: If there are unread replies, this is a link to them. + * - new_text: Text containing the translated, properly pluralized count. + * - created: Text representing when the topic was posted. Safe to output. + * - last_reply: Text representing when the topic was last replied to. + * - timestamp: The raw timestamp this topic was posted. + * - topic_id: Numeric ID for the current forum topic. + * + * @see template_preprocess() + * @see template_preprocess_forum_topic_list() + * + * @ingroup themeable + */ +#} + + + {{ header }} + + + {% for topic in topics %} + + + {% if topic.moved %} + + {% else %} + + + {% endif %} + + {% endfor %} + +
+ {{ topic.icon }} +
+
+ {{ topic.title }} +
+
+ {{ topic.created }} +
+
+
{{ topic.message }} + {{ topic.comment_count }} + {% if topic.new_replies %} +
+ {{ topic.new_text }} + {% endif %} +
{{ topic.last_reply }}
+{{ pager }} diff --git a/core/modules/forum/templates/forum-topic-list.tpl.php b/core/modules/forum/templates/forum-topic-list.tpl.php deleted file mode 100644 index 5130ed6..0000000 --- a/core/modules/forum/templates/forum-topic-list.tpl.php +++ /dev/null @@ -1,74 +0,0 @@ -icon: The icon to display. - * - $topic->moved: A flag to indicate whether the topic has been moved to - * another forum. - * - $topic->title: The title of the topic. Safe to output. - * - $topic->message: If the topic has been moved, this contains an - * explanation and a link. - * - $topic->zebra: 'even' or 'odd' string used for row class. - * - $topic->comment_count: The number of replies on this topic. - * - $topic->new_replies: A flag to indicate whether there are unread - * comments. - * - $topic->new_url: If there are unread replies, this is a link to them. - * - $topic->new_text: Text containing the translated, properly pluralized - * count. - * - $topic->created: A string representing when the topic was posted. Safe - * to output. - * - $topic->last_reply: An outputtable string representing when the topic was - * last replied to. - * - $topic->timestamp: The raw timestamp this topic was posted. - * - $topic_id: Numeric ID for the current forum topic. - * - * @see template_preprocess_forum_topic_list() - * @see theme_forum_topic_list() - * - * @ingroup themeable - */ -?> - - - - - - - - - moved): ?> - - - - - - - - -
- icon; ?> -
-
- title; ?> -
-
- created; ?> -
-
-
message; ?> - comment_count; ?> - new_replies): ?> -
- new_text; ?> - -
last_reply; ?>
- diff --git a/core/modules/forum/templates/forums.html.twig b/core/modules/forum/templates/forums.html.twig new file mode 100644 index 0000000..59fff7d --- /dev/null +++ b/core/modules/forum/templates/forums.html.twig @@ -0,0 +1,24 @@ +{# +/** + * @file + * Default theme implementation to display a forum. + * + * May contain forum containers as well as forum topics. + * + * Available variables: + * - forums: The forums to display (as processed by forum-list.html.twig). + * - topics: The topics to display (as processed by forum-topic-list.html.twig). + * - forums_defined: A flag to indicate that the forums are configured. + * + * @see template_preprocess() + * @see template_preprocess_forums() + * + * @ingroup themeable + */ +#} +{% if forums_defined %} +
+ {{ forums }} + {{ topics }} +
+{% endif %} diff --git a/core/modules/forum/templates/forums.tpl.php b/core/modules/forum/templates/forums.tpl.php deleted file mode 100644 index 6a0e02e..0000000 --- a/core/modules/forum/templates/forums.tpl.php +++ /dev/null @@ -1,24 +0,0 @@ - - -
- - -
- diff --git a/core/modules/jsonld/jsonld.info.yml b/core/modules/jsonld/jsonld.info.yml deleted file mode 100644 index c0623b6..0000000 --- a/core/modules/jsonld/jsonld.info.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: JSON-LD -type: module -description: 'Serializes entities using JSON-LD format.' -package: Core -version: VERSION -core: 8.x -dependencies: - - rdf - - serialization diff --git a/core/modules/jsonld/jsonld.module b/core/modules/jsonld/jsonld.module deleted file mode 100644 index b839e88..0000000 --- a/core/modules/jsonld/jsonld.module +++ /dev/null @@ -1,20 +0,0 @@ -' . t('The JSON-LD module serializes entities to the JSON-LD data format. To request JSON-LD instead of HTML, a client should add an Accept header to the request. This module will respond with JSON-LD if the Accept header value is one of the following: application/ld+json, which returns an easy-to-use data structure which is compatible with many external schemas, and application/vnd.drupal.ld+json, which is more expressive and is appropriate for content staging.', array( - '@jsonld_org' => 'http://json-ld.org/', - )) . '

'; - return $output; - } -} diff --git a/core/modules/jsonld/jsonld.services.yml b/core/modules/jsonld/jsonld.services.yml deleted file mode 100644 index 0359859..0000000 --- a/core/modules/jsonld/jsonld.services.yml +++ /dev/null @@ -1,39 +0,0 @@ -# Normalizers can be specified to support a particular class and format in -# Normalizer::supportsNormalization(). Since the first matching Normalizer -# is used, Normalizers should be ordered from most specific to least -# specific. -services: - serializer.normalizer.entity_reference.jsonld: - class: Drupal\jsonld\JsonldEntityReferenceNormalizer - tags: - - { name: normalizer, priority: 5 } - arguments: ['@rdf.site_schema_manager', '@rdf.mapping_manager'] - serializer.normalizer.field_item.jsonld: - class: Drupal\jsonld\JsonldFieldItemNormalizer - tags: - - { name: normalizer, priority: 5 } - arguments: ['@rdf.site_schema_manager', '@rdf.mapping_manager'] - serializer.normalizer.entity.jsonld: - class: Drupal\jsonld\JsonldEntityNormalizer - tags: - - { name: normalizer, priority: 5 } - arguments: ['@rdf.site_schema_manager', '@rdf.mapping_manager'] - serializer.normalizer.rdf_schema.jsonld: - class: Drupal\jsonld\JsonldRdfSchemaNormalizer - tags: - - { name: normalizer, priority: 5 } - arguments: ['@rdf.site_schema_manager', '@rdf.mapping_manager'] -# Add the encoder to the service container. Encoders can only specify which -# format they support in Encoder::supportsEncoding(). - serializer.encoder.jsonld: - class: Drupal\jsonld\JsonldEncoder - tags: - - { name: encoder, priority: 5, format: jsonld } - serializer.encoder.drupal_jsonld: - class: Drupal\jsonld\JsonldEncoder - tags: - - { name: encoder, priority: 5, format: drupal_jsonld } - jsonld.subscriber: - class: Drupal\jsonld\EventSubscriber\JsonldSubscriber - tags: - - { name: event_subscriber } diff --git a/core/modules/jsonld/lib/Drupal/jsonld/EventSubscriber/JsonldSubscriber.php b/core/modules/jsonld/lib/Drupal/jsonld/EventSubscriber/JsonldSubscriber.php deleted file mode 100644 index 38a06ec..0000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/EventSubscriber/JsonldSubscriber.php +++ /dev/null @@ -1,42 +0,0 @@ -getRequest(); - $request->setFormat('drupal_jsonld', 'application/vnd.drupal.ld+json'); - $request->setFormat('jsonld', 'application/ld+json'); - } - - /** - * Registers the methods in this class that should be listeners. - * - * @return array - * An array of event listener definitions. - */ - static function getSubscribedEvents() { - $events[KernelEvents::REQUEST][] = array('onKernelRequest', 40); - return $events; - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEncoder.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEncoder.php deleted file mode 100644 index 8aa289e..0000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEncoder.php +++ /dev/null @@ -1,40 +0,0 @@ -serializer, $this->siteSchemaManager); - - $attributes = $entity_wrapper->getProperties(); - $attributes = array( - '@id' => $entity_wrapper->getId(), - '@type' => $entity_wrapper->getTypeUri(), - ) + $attributes; - return $attributes; - } - - /** - * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize() - * - * @throws \Symfony\Component\Serializer\Exception\UnexpectedValueException - */ - public function denormalize($data, $class, $format = null, array $context = array()) { - if (!isset($data['@type'])) { - throw new UnexpectedValueException('JSON-LD @type parameter must be included.'); - } - - // Every bundle has a type, identified by URI. The incoming data should - // either include a type URI from this site's schema, or one of the type - // URIs in the incoming data must map to a site schema URI when passed - // through the RDF mapping manager. - $type_uris = is_array($data['@type']) ? $data['@type'] : array($data['@type']); - // If the RDF mapping manager can find a match to a site schema URI, it - // will return the corresponding Typed Data ids. Otherwise, throw an - // exception. - // @todo The @types might be CURIEs or aliases. Expand before trying to map. - try { - $typed_data_ids = $this->rdfMappingManager->getTypedDataIdsFromTypeUris($type_uris); - } - catch (RdfMappingException $e) { - throw new UnexpectedValueException($e->getMessage(), 0, $e); - } - - $values = array( - 'type' => $typed_data_ids['bundle'], - ); - // If the data specifies a default language, use it to create the entity. - if (isset($data['langcode'])) { - $values['langcode'] = $data['langcode'][LANGUAGE_NOT_SPECIFIED][0]['value']; - } - // Otherwise, if the default language is not specified but there are - // translations of field values, explicitly set the entity's default - // language to the site's default language. This is required to enable - // field translation on this entity. - else if ($this->containsTranslation($data)) { - $values['langcode'] = language(LANGUAGE_TYPE_CONTENT)->langcode; - } - $entity = entity_create($typed_data_ids['entity_type'], $values); - // Make sure all empty entity fields default to NULL, so that afterwards it - // is possible to determine which fields were part of the data (even if they - // are empty). - foreach ($entity as $name => $field) { - if ($field->isEmpty()) { - $field->setValue(NULL); - } - } - - // For each attribute in the JSON-LD, add the values as fields to the newly - // created entity. It is assumed that the JSON attribute names are the same - // as the site's field names. - // @todo Possibly switch to URI expansion of attribute names. - foreach ($data as $fieldName => $incomingFieldValues) { - // Skip the JSON-LD specific terms, which start with '@'. - if ($fieldName[0] === '@') { - continue; - } - // If the incoming value is an empty array we set the property to mark it - // for deletion. - if (empty($incomingFieldValues) && is_array($incomingFieldValues)) { - $entity->{$fieldName} = array(); - } - - // Figure out the designated class for this field type, which is used by - // the Serializer to determine which Denormalizer to use. - // @todo Is there a better way to get the field type's associated class? - $fieldItemClass = get_class($entity->get($fieldName)->offsetGet(0)); - - // Iterate through the language keyed values and add them to the entity. - // The vnd.drupal.ld+json mime type will always use language keys, per - // http://drupal.org/node/1838700. - foreach ($incomingFieldValues as $langcode => $incomingFieldItems) { - $fieldValue = $this->serializer->denormalize($incomingFieldItems, $fieldItemClass, $format); - $entity->getTranslation($langcode) - ->set($fieldName, $fieldValue); - } - } - return $entity; - } - - /** - * Determine whether incoming data contains translated content. - * - * @param array $data - * The incoming data. - * - * @return bool - * Whether or not this data contains translated content. - */ - protected function containsTranslation($data) { - // Langcodes which do not represent a translation of the entity. - $defaultLangcodes = array( - LANGUAGE_DEFAULT, - LANGUAGE_NOT_SPECIFIED, - LANGUAGE_NOT_APPLICABLE, - language(LANGUAGE_TYPE_CONTENT)->langcode, - ); - - // Combine the langcodes from the field value keys in a single array. - $fieldLangcodes = array(); - foreach ($data as $propertyName => $property) { - //@todo Once @context has been added, check whether this property - // corresponds to an annotation instead. This will allow us to support - // incoming data that doesn't use language annotations. - if ('@' !== $propertyName[0]) { - $fieldLangcodes += array_keys($property); - } - } - - $translationLangcodes = array_diff($fieldLangcodes, $defaultLangcodes); - return !empty($translationLangcodes); - } -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityReferenceNormalizer.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityReferenceNormalizer.php deleted file mode 100644 index 28f47ef..0000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityReferenceNormalizer.php +++ /dev/null @@ -1,61 +0,0 @@ -entity, $format, $this->serializer, $this->siteSchemaManager); - return array( - '@id' => $entity_wrapper->getId(), - ); - } - - /** - * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize() - */ - public function denormalize($data, $class, $format = null, array $context = array()) { - // @todo Support denormalization for Entity Reference. - return array(); - } - - /** - * Overrides \Drupal\jsonld\JsonldNormalizerBase::supportsDenormalization() - */ - public function supportsDenormalization($data, $type, $format = NULL) { - $reflection = new ReflectionClass($type); - return in_array($format, static::$format) && ($reflection->getName() == $this->supportedInterfaceOrClass || $reflection->isSubclassOf($this->supportedInterfaceOrClass)); - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php deleted file mode 100644 index f96f114..0000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php +++ /dev/null @@ -1,131 +0,0 @@ -entity = $entity; - $this->format = $format; - $this->serializer = $serializer; - $this->siteSchemaManager = $site_schema_manager; - } - - /** - * Get the Entity's URI for the @id attribute. - * - * @return string - * The URI of the entity. - */ - public function getId() { - $uri_info = $this->entity->uri(); - return url($uri_info['path'], array('absolute' => TRUE)); - } - - /** - * Get the type URI. - * - * @todo Once RdfMappingManager has a mapOutputTypes event, use that instead - * of simply returning the site schema URI. - */ - public function getTypeUri() { - $entity_type = $this->entity->entityType(); - $bundle = $this->entity->bundle(); - switch ($this->format) { - case 'drupal_jsonld': - $schema_path = SiteSchema::CONTENT_DEPLOYMENT; - break; - case 'jsonld': - $schema_path = SiteSchema::SYNDICATION; - } - $schema = $this->siteSchemaManager->getSchema($schema_path); - return $schema->bundle($entity_type, $bundle)->getUri(); - } - - /** - * Get properties, excluding JSON-LD specific properties. - * - * @return array - * An array of properties structured as in JSON-LD. - */ - public function getProperties() { - // Properties to skip. - $skip = array('id'); - $properties = array(); - - // Create language map property structure. - foreach ($this->entity->getTranslationLanguages() as $langcode => $language) { - foreach ($this->entity->getTranslation($langcode) as $name => $field) { - $definition = $this->entity->getPropertyDefinition($name); - $langKey = empty($definition['translatable']) ? LANGUAGE_NOT_SPECIFIED : $langcode; - if (!$field->isEmpty()) { - $properties[$name][$langKey] = $this->serializer->normalize($field, $this->format); - } - } - } - - // Only return properties which are not in the $skip array. - return array_diff_key($properties, array_fill_keys($skip, '')); - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldFieldItemNormalizer.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldFieldItemNormalizer.php deleted file mode 100644 index 1f1a1bb..0000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldFieldItemNormalizer.php +++ /dev/null @@ -1,42 +0,0 @@ -getPropertyValues(); - } - - /** - * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::denormalize() - */ - public function denormalize($data, $class, $format = null, array $context = array()) { - // For most fields, the field items array should simply be returned as is. - return $data; - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldNormalizerBase.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldNormalizerBase.php deleted file mode 100644 index 61741ee..0000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldNormalizerBase.php +++ /dev/null @@ -1,80 +0,0 @@ -siteSchemaManager = $site_schema_manager; - $this->rdfMappingManager = $rdf_mapping_manager; - } - - /** - * Implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface::normalize() - */ - public function supportsNormalization($data, $format = NULL) { - return is_object($data) && in_array($format, static::$format) && ($data instanceof $this->supportedInterfaceOrClass); - } - - /** - * Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() - * - * This class doesn't implement DenormalizerInterface, but most of its child - * classes do, so this method is implemented at this level to reduce code - * duplication. - */ - public function supportsDenormalization($data, $type, $format = NULL) { - $reflection = new ReflectionClass($type); - return in_array($format, static::$format) && $reflection->implementsInterface($this->supportedInterfaceOrClass); - } -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldRdfSchemaNormalizer.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldRdfSchemaNormalizer.php deleted file mode 100644 index 9315a58..0000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldRdfSchemaNormalizer.php +++ /dev/null @@ -1,51 +0,0 @@ -getGraph(); - - foreach ($graph as $term_uri => $properties) { - // JSON-LD uses the @type keyword as a stand-in for rdf:type. Replace any - // use of rdf:type and move the type to the front of the property array. - if (isset($properties[RdfConstants::RDF_TYPE])) { - $properties = array( - '@type' => $properties[RdfConstants::RDF_TYPE], - ) + $properties; - } - unset($properties[RdfConstants::RDF_TYPE]); - - // Add the @id keyword to the front of the array. - $normalized[] = array( - '@id' => $term_uri, - ) + $properties; - } - - return $normalized; - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/Tests/JsonldTestSetupHelper.php b/core/modules/jsonld/lib/Drupal/jsonld/Tests/JsonldTestSetupHelper.php deleted file mode 100644 index bf3a33b..0000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/Tests/JsonldTestSetupHelper.php +++ /dev/null @@ -1,99 +0,0 @@ -siteSchemaManager = new SiteSchemaManager($container->get('cache.cache')); - // Construct RDF mapping manager. - $dispatcher = new EventDispatcher(); - $dispatcher->addSubscriber(new MappingSubscriber()); - $this->rdfMappingManager = new RdfMappingManager($dispatcher, $this->siteSchemaManager); - // Construct normalizers. - $this->normalizers = array( - 'entityreference' => new JsonldEntityReferenceNormalizer($this->siteSchemaManager, $this->rdfMappingManager), - 'field_item' => new JsonldFieldItemNormalizer($this->siteSchemaManager, $this->rdfMappingManager), - 'entity' => new JsonldEntityNormalizer($this->siteSchemaManager, $this->rdfMappingManager), - ); - $serializer = new Serializer($this->normalizers, array(new JsonldEncoder())); - $this->normalizers['entity']->setSerializer($serializer); - } - - /** - * Get Normalizers. - * - * @return array - * An array of normalizers, keyed by supported class or interface. - */ - public function getNormalizers() { - return $this->normalizers; - } - - /** - * Get the SiteSchemaManager object. - * - * @return \Drupal\rdf\SiteSchema\SiteSchemaManager - * The SiteSchemaManager, which is also injected into the Normalizers. - */ - public function getSiteSchemaManager() { - return $this->siteSchemaManager; - } - - /** - * Get the RdfMappingManager object. - * - * @return \Drupal\rdf\RdfMappingManager - * The RdfMappingManager, which is also injected into the Normalizers. - */ - public function getRdfMappingManager() { - return $this->rdfMappingManager; - } -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/Tests/NormalizeDenormalizeTest.php b/core/modules/jsonld/lib/Drupal/jsonld/Tests/NormalizeDenormalizeTest.php deleted file mode 100644 index 0371ed9..0000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/Tests/NormalizeDenormalizeTest.php +++ /dev/null @@ -1,213 +0,0 @@ - 'Normalize/Denormalize Test', - 'description' => "Test that entities can be normalized/denormalized in JSON-LD.", - 'group' => 'JSON-LD', - ); - } - - /** - * Add the normalizer to be tested. - */ - function setUp() { - parent::setUp(); - - $setup_helper = new JsonldTestSetupHelper($this->container); - $this->normalizers = $setup_helper->getNormalizers(); - - // Add German as a language. - $language = new Language(array( - 'langcode' => 'de', - 'name' => 'Deutsch', - )); - language_save($language); - } - - /** - * Tests the normalize function. - */ - public function testNormalize() { - // Create a German entity. - $values = array( - 'langcode' => 'de', - 'name' => $this->randomName(), - 'user_id' => $GLOBALS['user']->uid, - 'field_test_text' => array( - 'value' => $this->randomName(), - 'format' => 'full_html', - ), - ); - // Array of translated values. - $translationValues = array( - 'name' => $this->randomName(), - ); - - $entity = entity_create('entity_test', $values); - $entity->save(); - // Add an English value for name property. - $entity->getTranslation('en')->set('name', array(0 => array('value' => $translationValues['name']))); - - $expectedArray = array( - '@id' => $this->getEntityId($entity), - 'uuid' => array( - 'und' => array( - array( - 'value' => $entity->uuid(), - ), - ), - ), - 'user_id' => array( - 'de' => array( - array( - '@id' => url('user/' . $values['user_id'], array('absolute' => TRUE)), - ), - ), - ), - 'name' => array( - 'de' => array( - array( - 'value' => $values['name'], - ), - ), - 'en' => array( - array( - 'value' => $translationValues['name'], - ), - ), - ), - 'field_test_text' => array( - 'und' => array( - array( - 'value' => $values['field_test_text']['value'], - 'format' => $values['field_test_text']['format'], - ), - ), - ), - ); - - $normalized = $this->normalizers['entity']->normalize($entity, static::$format); - // Test ordering. The @context and @id properties should always be first. - $keys = array_keys($normalized); - $this->assertEqual($keys[0], '@id', '@id and @context attributes placed correctly.'); - // Test @id value. - $this->assertEqual($normalized['@id'], $expectedArray['@id'], '@id uses correct value.'); - // Test non-translatable field. - $this->assertEqual($normalized['uuid'], $expectedArray['uuid'], 'Non-translatable fields are nested correctly.'); - // Test single-language translatable. - $this->assertEqual($normalized['user_id'], $expectedArray['user_id'], 'Translatable field with single language value is nested correctly.'); - // Test multi-language translatable. - $this->assertEqual($normalized['name'], $expectedArray['name'], 'Translatable field with multiple language values is nested correctly.'); - // Test multi-property untranslatable field. - $this->assertEqual($normalized['field_test_text'], $expectedArray['field_test_text'], 'Field with properties is nested correctly.'); - } - - function testDenormalize() { - $schema = new SiteSchema(SiteSchema::CONTENT_DEPLOYMENT); - $bundle_uri = $schema->bundle('entity_test', 'entity_test')->getUri(); - $incoming_data = array( - '@type' => $bundle_uri, - 'name' => array( - 'en' => array( - array( - 'value' => $this->randomName(), - ), - ), - 'de' => array( - array( - 'value' => $this->randomName(), - ), - ), - ), - 'field_test_text' => array( - 'und' => array( - array( - 'value' => $this->randomName(), - 'format' => 'full_html', - ), - ), - ), - ); - - // Test valid request. - $entity = $this->normalizers['entity']->denormalize($incoming_data, 'Drupal\Core\Entity\EntityNG', static::$format); - $this->assertEqual('entity_test', $entity->bundle(), "Denormalize creates entity with correct bundle."); - $this->assertEqual($incoming_data['name']['en'], $entity->get('name')->getValue(), "Translatable field denormalized correctly in default language."); - $this->assertEqual($incoming_data['name']['de'], $entity->getTranslation('de')->get('name')->getValue(), "Translatable field denormalized correctly in translation language."); - $this->assertEqual($incoming_data['field_test_text']['und'], $entity->get('field_test_text')->getValue(), "Untranslatable field denormalized correctly."); - - // Test request without @type. - unset($incoming_data['@type']); - try { - $this->normalizers['entity']->denormalize($incoming_data, 'Drupal\Core\Entity\EntityNG', static::$format); - $this->fail('Trying to denormalize entity data without @type results in exception.'); - } - catch (UnexpectedValueException $e) { - $this->pass('Trying to denormalize entity data without @type results in exception.'); - } - - // Test request with @type that has no valid mapping. - $incoming_data['@type'] = 'http://failing-uri.com/type'; - try { - $this->normalizers['entity']->denormalize($incoming_data, 'Drupal\Core\Entity\EntityNG', static::$format); - $this->fail('Trying to denormalize entity data with unrecognized @type results in exception.'); - } - catch (UnexpectedValueException $e) { - $this->pass('Trying to denormalize entity data with unrecognized @type results in exception.'); - } - } - - /** - * Get the Entity ID. - * - * @param \Drupal\Core\Entity\EntityNG $entity - * Entity to get URI for. - * - * @return string - * Return the entity URI. - */ - protected function getEntityId($entity) { - global $base_url; - $uriInfo = $entity->uri(); - return $base_url . '/' . $uriInfo['path']; - } - -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/Tests/RdfSchemaSerializationTest.php b/core/modules/jsonld/lib/Drupal/jsonld/Tests/RdfSchemaSerializationTest.php deleted file mode 100644 index e5349f1..0000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/Tests/RdfSchemaSerializationTest.php +++ /dev/null @@ -1,56 +0,0 @@ - 'Site schema JSON-LD serialization', - 'description' => 'Tests the JSON-LD serialization of the RDF site schema.', - 'group' => 'JSON-LD', - ); - } - - /** - * Tests the serialization of site schemas. - */ - function testSchemaSerialization() { - // url() requires the {url_alias} table. - $this->installSchema('system', 'url_alias'); - - $entity_type = $bundle = 'entity_test'; - - // Set up the bundle schema for the entity_test bundle. - $schema = new SiteSchema(SiteSchema::CONTENT_DEPLOYMENT); - $bundle_schema = $schema->bundle($entity_type, $bundle); - // Set up the serializer. - $setup_helper = new JsonldTestSetupHelper($this->container); - $normalizer = new JsonldRdfSchemaNormalizer($setup_helper->getSiteSchemaManager(), $setup_helper->getRdfMappingManager()); - $serializer = new Serializer(array($normalizer), array(new JsonldEncoder())); - - $serialized = $serializer->serialize($bundle_schema, 'jsonld'); - $decoded = json_decode($serialized); - $parsed_term = $decoded[0]; - - $this->assertEqual($parsed_term->{'@id'}, $bundle_schema->getUri(), 'JSON-LD for schema term uses correct @id.'); - $this->assertEqual($parsed_term->{'@type'}, 'http://www.w3.org/2000/01/rdf-schema#class', 'JSON-LD for schema term uses correct @type.'); - // The @id and @type should be placed in the beginning of the array. - $array_keys = array_keys((array) $parsed_term); - $this->assertEqual(array('@id', '@type'), array_slice($array_keys, 0, 2), 'JSON-LD keywords are placed before other properties.'); - $this->assertTrue(isset($parsed_term->{'http://www.w3.org/2000/01/rdf-schema#isDefinedBy'}), 'Other properties of the term are included.'); - } -} diff --git a/core/modules/jsonld/lib/Drupal/jsonld/Tests/SupportsSerializationTest.php b/core/modules/jsonld/lib/Drupal/jsonld/Tests/SupportsSerializationTest.php deleted file mode 100644 index d9d4a7f..0000000 --- a/core/modules/jsonld/lib/Drupal/jsonld/Tests/SupportsSerializationTest.php +++ /dev/null @@ -1,96 +0,0 @@ - 'Supports class/format serialization test', - 'description' => "Test that normalizers and encoders support expected classes and formats.", - 'group' => 'JSON-LD', - ); - } - - /** - * Add the normalizer to be tested. - */ - function setUp() { - parent::setUp(); - - $setup_helper = new JsonldTestSetupHelper($this->container); - $this->normalizers = $setup_helper->getNormalizers(); - } - - /** - * Tests the supportsNormalization function. - */ - public function testSupportsNormalization() { - $format = static::$format; - $supportedEntity = entity_create('entity_test', array()); - $unsupportedEntity = new ConfigEntityTest(); - $field = $supportedEntity->get('uuid'); - $entityreferenceField = $supportedEntity->get('user_id'); - - // Supported entity. - $this->assertTrue($this->normalizers['entity']->supportsNormalization($supportedEntity, static::$format), "Entity normalization is supported for $format on content entities."); - // Unsupported entity. - $this->assertFalse($this->normalizers['entity']->supportsNormalization($unsupportedEntity, static::$format), "Normalization is not supported for other entity types."); - - // Field item. - $this->assertTrue($this->normalizers['field_item']->supportsNormalization($field->offsetGet(0), static::$format), "Field item normalization is supported for $format."); - // Entity reference field item. - $this->assertTrue($this->normalizers['entityreference']->supportsNormalization($entityreferenceField->offsetGet(0), static::$format), "Entity reference field item normalization is supported for $format."); - } - - /** - * Tests the supportsDenormalization function. - */ - public function testSupportsDenormalization() { - $format = static::$format; - $data = array(); - $supportedEntityClass = 'Drupal\Core\Entity\EntityNG'; - $unsupportedEntityClass = 'Drupal\config\Tests\ConfigEntityTest'; - $fieldClass = 'Drupal\Core\Entity\Field\Type\StringItem'; - $entityreferenceFieldClass = 'Drupal\Core\Entity\Field\Type\EntityReferenceItem'; - - // Supported entity. - $this->assertTrue($this->normalizers['entity']->supportsDenormalization($data, $supportedEntityClass, static::$format), "Entity denormalization is supported for $format on content entities."); - // Unsupported entity. - $this->assertFalse($this->normalizers['entity']->supportsDenormalization($data, $unsupportedEntityClass, static::$format), "Denormalization is not supported for other entity types."); - - // Field item. - $this->assertTrue($this->normalizers['field_item']->supportsDenormalization($data, $fieldClass, static::$format), "Field item denormalization is supported for $format."); - // Entity reference field item. - $this->assertTrue($this->normalizers['entityreference']->supportsDenormalization($data, $entityreferenceFieldClass, static::$format), "Entity reference field item denormalization is supported for $format."); - } - -} diff --git a/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php b/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php deleted file mode 100644 index 123493b..0000000 --- a/core/modules/rdf/lib/Drupal/rdf/EventSubscriber/RouteSubscriber.php +++ /dev/null @@ -1,78 +0,0 @@ -siteSchemaManager = $site_schema_manager; - } - - /** - * Adds routes for term types in the site-generated schemas. - * - * @param \Drupal\Core\Routing\RouteBuildEvent $event - * The route building event. - */ - public function routes(RouteBuildEvent $event) { - - $collection = $event->getRouteCollection(); - - // Add the routes for all of the terms in both schemas. - foreach ($this->siteSchemaManager->getSchemas() as $schema) { - $routes = $schema->getRoutes(); - foreach ($routes as $controller => $pattern) { - $schema_path = $schema->getPath(); - $route = new Route($pattern, array( - '_controller' => 'Drupal\rdf\SiteSchema\SchemaController::' . $controller, - 'schema_path' => $schema_path, - ), array( - '_method' => 'GET', - '_access' => 'TRUE', - )); - // Create the route name to use in the RouteCollection. Remove the - // trailing slash and replace characters, so that a path such as - // site-schema/syndication/ becomes rdf.site_schema.syndication. - $route_name = 'rdf.' . str_replace(array('-','/'), array('_', '.'), substr_replace($schema_path ,"",-1)); - $collection->add($route_name, $route); - } - } - } - - /** - * Implements EventSubscriberInterface::getSubscribedEvents(). - */ - static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'routes'; - return $events; - } -} - diff --git a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php b/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php deleted file mode 100644 index acd3f8e..0000000 --- a/core/modules/rdf/lib/Drupal/rdf/SiteSchema/SchemaController.php +++ /dev/null @@ -1,69 +0,0 @@ -container = $container; - } - - /** - * Responds to a schema request for a bundle of a given entity type. - * - * @param string $entity_type - * The entity type. - * @param string $bundle - * The entity bundle. - * @param string $schema_path - * The relative base path for the schema. - * - * @return \Symfony\Component\HttpFoundation\Response - * The response object. - * - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException - */ - public function bundle($entity_type, $bundle, $schema_path) { - if (!$entity_info = entity_get_info($entity_type)) { - throw new NotFoundHttpException(t('Entity type @entity_type not found', array('@entity_type' => $entity_type))); - } - if (!array_key_exists($bundle, entity_get_bundles($entity_type))) { - throw new NotFoundHttpException(t('Bundle @bundle not found', array('@bundle' => $bundle))); - } - - $serializer = $this->container->get('serializer'); - $site_schema_manager = $this->container->get('rdf.site_schema_manager'); - $schema = $site_schema_manager->getSchema($schema_path); - // @todo Remove hard-coded mimetype once we have proper conneg. - $content = $serializer->serialize($schema->bundle($entity_type, $bundle), 'jsonld'); - return new Response($content, 200, array('Content-type' => 'application/json')); - } - -} diff --git a/core/modules/rdf/rdf.services.yml b/core/modules/rdf/rdf.services.yml index 7b3a515..9777720 100644 --- a/core/modules/rdf/rdf.services.yml +++ b/core/modules/rdf/rdf.services.yml @@ -9,8 +9,3 @@ services: class: Drupal\rdf\EventSubscriber\MappingSubscriber tags: - { name: event_subscriber } - rdf.route_subscriber: - class: Drupal\rdf\EventSubscriber\RouteSubscriber - tags: - - { name: event_subscriber } - arguments: ['@rdf.site_schema_manager']