Commit 53d8c24d authored by webchick's avatar webchick

Issue #1818560 by Berdir, fago, Wim Leers, jessebeach, dawehner, YesCT:...

Issue #1818560 by Berdir, fago, Wim Leers, jessebeach, dawehner, YesCT: Convert taxonomy entities to the new Entity Field API.
parent 9f59d345
......@@ -96,9 +96,13 @@ public function __construct($entityType) {
*/
public function create(array $values) {
// We have to determine the bundle first.
// @todo Throw an exception if no bundle is passed and we have a bundle key
// defined.
$bundle = $this->bundleKey ? $values[$this->bundleKey] : FALSE;
$bundle = FALSE;
if ($this->bundleKey) {
if (!isset($values[$this->bundleKey])) {
throw new EntityStorageException(t('Missing bundle for entity type @type', array('@type' => $this->entityType)));
}
$bundle = $values[$this->bundleKey];
}
$entity = new $this->entityClass(array(), $this->entityType, $bundle);
// Set all other given values.
......
......@@ -74,7 +74,7 @@ public function testEntityReferenceItem() {
$this->assertTrue($entity->field_test_taxonomy instanceof FieldInterface, 'Field implements interface.');
$this->assertTrue($entity->field_test_taxonomy[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_test_taxonomy->target_id, $tid);
$this->assertEqual($entity->field_test_taxonomy->entity->name, $this->term->name);
$this->assertEqual($entity->field_test_taxonomy->entity->name->value, $this->term->name->value);
$this->assertEqual($entity->field_test_taxonomy->entity->id(), $tid);
$this->assertEqual($entity->field_test_taxonomy->entity->uuid(), $this->term->uuid());
......@@ -84,18 +84,18 @@ public function testEntityReferenceItem() {
$entity->field_test_taxonomy->entity->save();
// Verify it is the correct name.
$term = entity_load('taxonomy_term', $tid);
$this->assertEqual($term->name, $new_name);
$this->assertEqual($term->name->value, $new_name);
// Make sure the computed term reflects updates to the term id.
$term2 = entity_create('taxonomy_term', array(
'name' => $this->randomName(),
'vid' => $this->term->vid,
'vid' => $this->term->bundle(),
'langcode' => LANGUAGE_NOT_SPECIFIED,
));
$term2->save();
$entity->field_test_taxonomy->target_id = $term2->id();
$this->assertEqual($entity->field_test_taxonomy->entity->id(), $term2->id());
$this->assertEqual($entity->field_test_taxonomy->entity->name, $term2->name);
$this->assertEqual($entity->field_test_taxonomy->entity->name->value, $term2->name->value);
}
}
......@@ -5,28 +5,32 @@
* Administrative page callbacks for the Forum module.
*/
use Drupal\taxonomy\Plugin\Core\Entity\Term;
/**
* Page callback: Returns a form for creating a new forum or container.
*
* @param $type
* What is being added. Possible values are 'forum' and 'container'.
* @param $edit
* (optional) Associative array containing a forum term to be edited.
* Defaults to an empty array.
* @param \Drupal\taxonomy\Plugin\Core\Entity\Term $term
* (optional) A forum or container term to be edited. Defaults to NULL.
*
* @return
* A form for creating a new forum or container.
*
* @see forum_menu()
*/
function forum_form_main($type, $edit = array()) {
$edit = (array) $edit;
function forum_form_main($type, Term $term = NULL) {
if (!$term) {
$term = entity_create('taxonomy_term', array('vid' => config('forum.settings')->get('vocabulary')));
}
switch ($type) {
case 'forum':
return drupal_get_form('forum_form_forum', $edit);
return drupal_get_form('forum_form_forum', $term);
break;
case 'container':
return drupal_get_form('forum_form_container', $edit);
return drupal_get_form('forum_form_container', $term);
break;
}
}
......@@ -34,37 +38,30 @@ function forum_form_main($type, $edit = array()) {
/**
* Form constructor for adding and editing a forum.
*
* @param $edit
* (optional) Associative array containing a forum term to be added or edited.
* Defaults to an empty array.
* @param \Drupal\taxonomy\Plugin\Core\Entity\Term $term
* A forum term to be edited.
*
* @see forum_form_submit()
* @ingroup forms
*/
function forum_form_forum($form, &$form_state, $edit = array()) {
$edit += array(
'name' => '',
'description' => '',
'tid' => NULL,
'weight' => 0,
);
function forum_form_forum($form, &$form_state, Term $term) {
$form['name'] = array('#type' => 'textfield',
'#title' => t('Forum name'),
'#default_value' => $edit['name'],
'#default_value' => $term->name->value,
'#maxlength' => 255,
'#description' => t('Short but meaningful name for this collection of threaded discussions.'),
'#required' => TRUE,
);
$form['description'] = array('#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $edit['description'],
'#default_value' => $term->description->value,
'#description' => t('Description and guidelines for discussions within this forum.'),
);
$form['parent']['#tree'] = TRUE;
$form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'forum');
$form['parent'][0] = _forum_parent_select($term->id(), t('Parent'), 'forum');
$form['weight'] = array('#type' => 'weight',
'#title' => t('Weight'),
'#default_value' => $edit['weight'],
'#default_value' => $term->weight->value,
'#description' => t('Forums are displayed in ascending order by weight (forums with equal weights are displayed alphabetically).'),
);
......@@ -76,13 +73,13 @@ function forum_form_forum($form, &$form_state, $edit = array()) {
'#button_type' => 'primary',
'#submit' => array('forum_form_submit')
);
if ($edit['tid']) {
if (!$term->isNew()) {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#submit' => array('forum_forum_delete'),
);
$form['tid'] = array('#type' => 'value', '#value' => $edit['tid']);
$form['tid'] = array('#type' => 'value', '#value' => $term->id());
}
$form['#theme'] = 'forum_form';
......@@ -111,10 +108,10 @@ function forum_form_submit($form, &$form_state) {
case SAVED_NEW:
if ($container) {
$containers = $config->get('containers');
$containers[] = $term->tid;
$containers[] = $term->id();
$config->set('containers', $containers)->save();
}
$form_state['values']['tid'] = $term->tid;
$form_state['values']['tid'] = $term->id();
drupal_set_message(t('Created new @type %term.', array('%term' => $form_state['values']['name'], '@type' => $type)));
break;
case SAVED_UPDATED:
......@@ -145,26 +142,19 @@ function theme_forum_form($variables) {
/**
* Form constructor for adding and editing forum containers.
*
* @param $edit
* (optional) Associative array containing a container term to be added or edited.
* Defaults to an empty array.
* @param \Drupal\taxonomy\Plugin\Core\Entity\Term $term
* A container term to be edited.
*
* @see forum_form_submit()
* @ingroup forms
*/
function forum_form_container($form, &$form_state, $edit = array()) {
function forum_form_container($form, &$form_state, Term $term) {
$config = config('forum.settings');
$edit += array(
'name' => '',
'description' => '',
'tid' => NULL,
'weight' => 0,
);
// Handle a delete operation.
$form['name'] = array(
'#title' => t('Container name'),
'#type' => 'textfield',
'#default_value' => $edit['name'],
'#default_value' => $term->name->value,
'#maxlength' => 255,
'#description' => t('Short but meaningful name for this collection of related forums.'),
'#required' => TRUE
......@@ -173,15 +163,15 @@ function forum_form_container($form, &$form_state, $edit = array()) {
$form['description'] = array(
'#type' => 'textarea',
'#title' => t('Description'),
'#default_value' => $edit['description'],
'#default_value' => $term->description->value,
'#description' => t('Description and guidelines for forums within this container.')
);
$form['parent']['#tree'] = TRUE;
$form['parent'][0] = _forum_parent_select($edit['tid'], t('Parent'), 'container');
$form['parent'][0] = _forum_parent_select($term->id(), t('Parent'), 'container');
$form['weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#default_value' => $edit['weight'],
'#default_value' => $term->weight->value,
'#description' => t('Containers are displayed in ascending order by weight (containers with equal weights are displayed alphabetically).')
);
......@@ -196,13 +186,13 @@ function forum_form_container($form, &$form_state, $edit = array()) {
'#button_type' => 'primary',
'#submit' => array('forum_form_submit'),
);
if ($edit['tid']) {
if (!$term->isNew()) {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#submit' => array('forum_forum_delete'),
);
$form['tid'] = array('#type' => 'value', '#value' => $edit['tid']);
$form['tid'] = array('#type' => 'value', '#value' => $term->id());
}
$form['#theme'] = 'forum_form';
......@@ -240,18 +230,18 @@ function forum_overview($form, &$form_state) {
foreach (element_children($form['terms']) as $key) {
if (isset($form['terms'][$key]['#term'])) {
$term = $form['terms'][$key]['#term'];
$form['terms'][$key]['term']['#href'] = 'forum/' . $term['tid'];
$form['terms'][$key]['term']['#href'] = 'forum/' . $term->id();
unset($form['terms'][$key]['operations']['#links']['delete']);
if (in_array($form['terms'][$key]['#term']['tid'], $config->get('containers'))) {
if (in_array($form['terms'][$key]['#term']->id(), $config->get('containers'))) {
$form['terms'][$key]['operations']['#links']['edit']['title'] = t('edit container');
$form['terms'][$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/container/' . $term['tid'];
$form['terms'][$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/container/' . $term->id();
// We don't want the redirect from the link so we can redirect the
// delete action.
unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']);
}
else {
$form['terms'][$key]['operations']['#links']['edit']['title'] = t('edit forum');
$form['terms'][$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/forum/' . $term['tid'];
$form['terms'][$key]['operations']['#links']['edit']['href'] = 'admin/structure/forum/edit/forum/' . $term->id();
// We don't want the redirect from the link so we can redirect the
// delete action.
unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']);
......@@ -286,7 +276,7 @@ function _forum_parent_select($tid, $title, $child_type) {
$parents = taxonomy_term_load_parents($tid);
if ($parents) {
$parent = array_shift($parents);
$parent = $parent->tid;
$parent = $parent->id();
}
else {
$parent = 0;
......@@ -297,7 +287,7 @@ function _forum_parent_select($tid, $title, $child_type) {
// A term can't be the child of itself, nor of its children.
foreach ($children as $child) {
$exclude[] = $child->tid;
$exclude[] = $child->id();
}
$exclude[] = $tid;
......@@ -305,8 +295,8 @@ function _forum_parent_select($tid, $title, $child_type) {
$options[0] = '<' . t('root') . '>';
if ($tree) {
foreach ($tree as $term) {
if (!in_array($term->tid, $exclude)) {
$options[$term->tid] = str_repeat(' -- ', $term->depth) . $term->label();
if (!in_array($term->id(), $exclude)) {
$options[$term->id()] = str_repeat(' -- ', $term->depth) . $term->label();
}
}
}
......
......@@ -168,7 +168,7 @@ function forum_menu_local_tasks(&$data, $router_item, $root_path) {
// Add action link to 'node/add/forum' on 'forum' sub-pages.
if ($root_path == 'forum' || $root_path == 'forum/%') {
$tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->tid : 0);
$tid = (isset($router_item['page_arguments'][0]) ? $router_item['page_arguments'][0]->id() : 0);
$forum_term = forum_forum_load($tid);
if ($forum_term) {
$links = array();
......@@ -180,7 +180,7 @@ function forum_menu_local_tasks(&$data, $router_item, $root_path) {
'#theme' => 'menu_local_action',
'#link' => array(
'title' => t('Add new @node_type', array('@node_type' => node_type_get_label($type))),
'href' => 'node/add/' . $type . '/' . $forum_term->tid,
'href' => 'node/add/' . $type . '/' . $forum_term->id(),
),
);
}
......@@ -242,7 +242,7 @@ function forum_entity_bundle_info_alter(&$bundles) {
*/
function forum_uri($forum) {
return array(
'path' => 'forum/' . $forum->tid,
'path' => 'forum/' . $forum->id(),
);
}
......@@ -275,7 +275,7 @@ function forum_node_view(EntityInterface $node, EntityDisplay $display, $view_mo
if ($parents = taxonomy_term_load_parents_all($node->forum_tid)) {
$parents = array_reverse($parents);
foreach ($parents as $parent) {
$breadcrumb[] = l($parent->label(), 'forum/' . $parent->tid);
$breadcrumb[] = l($parent->label(), 'forum/' . $parent->id());
}
}
drupal_set_breadcrumb($breadcrumb);
......@@ -310,10 +310,10 @@ function forum_node_validate(EntityInterface $node, $form) {
continue;
}
$used = db_query_range('SELECT 1 FROM {taxonomy_term_data} WHERE tid = :tid AND vid = :vid', 0, 1, array(
':tid' => $term->tid,
':tid' => $term->id(),
':vid' => $term->bundle(),
))->fetchField();
if ($used && in_array($term->tid, $containers)) {
if ($used && in_array($term->id(), $containers)) {
form_set_error('taxonomy_forums', t('The item %forum is a forum container, not a forum. Select one of the forums below instead.', array('%forum' => $term->label())));
}
}
......@@ -479,7 +479,7 @@ function forum_taxonomy_term_delete(Term $term) {
// For containers, remove the tid from the forum_containers variable.
$config = config('forum.settings');
$containers = $config->get('containers');
$key = array_search($term->tid, $containers);
$key = array_search($term->id(), $containers);
if ($key !== FALSE) {
unset($containers[$key]);
}
......@@ -722,16 +722,17 @@ function forum_forum_load($tid = NULL) {
elseif ($tid === 0) {
$forum_term = entity_create('taxonomy_term', array(
'tid' => 0,
'vid' => $vid,
));
}
// Determine if the requested term is a container.
if (!$forum_term->tid || in_array($forum_term->tid, $config->get('containers'))) {
if (!$forum_term->id() || in_array($forum_term->id(), $config->get('containers'))) {
$forum_term->container = 1;
}
// Load parent terms.
$forum_term->parents = taxonomy_term_load_parents_all($forum_term->tid);
$forum_term->parents = taxonomy_term_load_parents_all($forum_term->id());
// Load the tree below.
$forums = array();
......@@ -754,14 +755,14 @@ function forum_forum_load($tid = NULL) {
foreach ($_forums as $forum) {
// Determine if the child term is a container.
if (in_array($forum->tid, $config->get('containers'))) {
if (in_array($forum->id(), $config->get('containers'))) {
$forum->container = 1;
}
// Merge in the topic and post counters.
if (!empty($counts[$forum->tid])) {
$forum->num_topics = $counts[$forum->tid]->topic_count;
$forum->num_posts = $counts[$forum->tid]->topic_count + $counts[$forum->tid]->comment_count;
if (!empty($counts[$forum->id()])) {
$forum->num_topics = $counts[$forum->id()]->topic_count;
$forum->num_posts = $counts[$forum->id()]->topic_count + $counts[$forum->id()]->comment_count;
}
else {
$forum->num_topics = 0;
......@@ -770,7 +771,7 @@ function forum_forum_load($tid = NULL) {
// Query "Last Post" information for this forum.
$query = db_select('node', 'n');
$query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', array(':tid' => $forum->tid));
$query->join('forum', 'f', 'n.vid = f.vid AND f.tid = :tid', array(':tid' => $forum->id()));
$query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid');
$query->join('users', 'u', 'ncs.last_comment_uid = u.uid');
$query->addExpression('CASE ncs.last_comment_uid WHEN 0 THEN ncs.last_comment_name ELSE u.name END', 'last_comment_name');
......@@ -793,7 +794,7 @@ function forum_forum_load($tid = NULL) {
}
$forum->last_post = $last_post;
$forums[$forum->tid] = $forum;
$forums[$forum->id()] = $forum;
}
// Cache the result, and return the tree.
......@@ -1054,8 +1055,8 @@ function template_preprocess_forum_list(&$variables) {
$row = 0;
// Sanitize each forum so that the template can safely print the data.
foreach ($variables['forums'] as $id => $forum) {
$variables['forums'][$id]->description = !empty($forum->description) ? filter_xss_admin($forum->description) : '';
$variables['forums'][$id]->link = url("forum/$forum->tid");
$variables['forums'][$id]->description = filter_xss_admin($forum->description->value);
$variables['forums'][$id]->link = url("forum/" . $forum->id());
$variables['forums'][$id]->name = check_plain($forum->label());
$variables['forums'][$id]->is_container = !empty($forum->container);
$variables['forums'][$id]->zebra = $row % 2 == 0 ? 'odd' : 'even';
......@@ -1068,10 +1069,10 @@ function template_preprocess_forum_list(&$variables) {
$variables['forums'][$id]->icon_class = 'default';
$variables['forums'][$id]->icon_title = t('No new posts');
if ($user->uid) {
$variables['forums'][$id]->new_topics = _forum_topics_unread($forum->tid, $user->uid);
$variables['forums'][$id]->new_topics = _forum_topics_unread($forum->id(), $user->uid);
if ($variables['forums'][$id]->new_topics) {
$variables['forums'][$id]->new_text = format_plural($variables['forums'][$id]->new_topics, '1 new post<span class="element-invisible"> in forum %title</span>', '@count new posts<span class="element-invisible"> in forum %title</span>', array('%title' => $variables['forums'][$id]->name));
$variables['forums'][$id]->new_url = url("forum/$forum->tid", array('fragment' => 'new'));
$variables['forums'][$id]->new_text = format_plural($variables['forums'][$id]->new_topics, '1 new post<span class="element-invisible"> in forum %title</span>', '@count new posts<span class="element-invisible"> in forum %title</span>', array('%title' => $variables['forums'][$id]->label()));
$variables['forums'][$id]->new_url = url('forum/' . $forum->id(), array('fragment' => 'new'));
$variables['forums'][$id]->icon_class = 'new';
$variables['forums'][$id]->icon_title = t('New posts');
}
......
......@@ -30,21 +30,21 @@ function forum_page($forum_term = NULL) {
// Breadcrumb navigation.
$breadcrumb[] = l(t('Home'), NULL);
if ($forum_term->tid) {
if ($forum_term->id()) {
// Parent of all forums is the vocabulary name.
$breadcrumb[] = l($vocabulary->label(), 'forum');
}
// Add all parent forums to breadcrumbs.
if ($forum_term->parents) {
foreach (array_reverse($forum_term->parents) as $parent) {
if ($parent->id() != $forum_term->tid) {
if ($parent->id() != $forum_term->id()) {
$breadcrumb[] = l($parent->label(), 'forum/' . $parent->id());
}
}
}
drupal_set_breadcrumb($breadcrumb);
if ($forum_term->tid && array_search($forum_term->tid, $config->get('containers')) === FALSE) {
if ($forum_term->id() && array_search($forum_term->id(), $config->get('containers')) === FALSE) {
// Add RSS feed for forums.
drupal_add_feed('taxonomy/term/' . $forum_term->id() . '/feed', 'RSS - ' . $forum_term->label());
}
......@@ -58,7 +58,7 @@ function forum_page($forum_term = NULL) {
$sort_by = $config->get('topics.order');
if (empty($forum_term->container)) {
$topics = forum_get_topics($forum_term->tid, $sort_by, $forum_per_page);
$topics = forum_get_topics($forum_term->id(), $sort_by, $forum_per_page);
}
else {
$topics = '';
......@@ -69,7 +69,7 @@ function forum_page($forum_term = NULL) {
'#forums' => $forum_term->forums,
'#topics' => $topics,
'#parents' => $forum_term->parents,
'#tid' => $forum_term->tid,
'#tid' => $forum_term->id(),
'#sortby' => $sort_by,
'#forums_per_page' => $forum_per_page,
);
......
......@@ -240,10 +240,10 @@ function testForum() {
function testAddOrphanTopic() {
// Must remove forum topics to test creating orphan topics.
$vid = config('forum.settings')->get('vocabulary');
$tree = taxonomy_get_tree($vid);
foreach ($tree as $term) {
taxonomy_term_delete($term->tid);
}
$tids = \Drupal::entityQuery('taxonomy_term')
->condition('vid', $vid)
->execute();
taxonomy_term_delete_multiple($tids);
// Create an orphan forum item.
$this->drupalLogin($this->admin_user);
......
......@@ -55,8 +55,8 @@
<span class="element-invisible"><?php print $forum->icon_title; ?></span>
</div>
<div class="name"><a href="<?php print $forum->link; ?>"><?php print $forum->label(); ?></a></div>
<?php if ($forum->description): ?>
<div class="description"><?php print $forum->description; ?></div>
<?php if ($forum->description->value): ?>
<div class="description"><?php print $forum->description->value; ?></div>
<?php endif; ?>
<?php print str_repeat('</div>', $forum->depth); ?>
</td>
......
......@@ -61,7 +61,7 @@ function hook_options_list($field, $instance, $entity) {
$terms = taxonomy_get_tree($tree['vid'], $tree['parent'], NULL, TRUE);
if ($terms) {
foreach ($terms as $term) {
$options[$term->tid] = str_repeat('-', $term->depth) . $term->label();
$options[$term->id()] = str_repeat('-', $term->depth) . $term->label();
}
}
}
......
<?php
/**
* @file
* Contains \Drupal\path\Type\PathItem.
*/
namespace Drupal\path\Type;
use Drupal\Core\Entity\Field\FieldItemBase;
/**
* Defines the 'path_field' entity field item.
*/
class PathItem extends FieldItemBase {
/**
* Definitions of the contained properties.
*
* @see PathItem::getPropertyDefinitions()
*
* @var array
*/
static $propertyDefinitions;
/**
* Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions().
*/
public function getPropertyDefinitions() {
if (!isset(static::$propertyDefinitions)) {
static::$propertyDefinitions['alias'] = array(
'type' => 'string',
'label' => t('Path alias'),
);
static::$propertyDefinitions['pid'] = array(
'type' => 'integer',
'label' => t('Path id'),
);
}
return static::$propertyDefinitions;
}
}
......@@ -232,13 +232,13 @@ function path_form_taxonomy_term_form_alter(&$form, $form_state) {
// Make sure this does not show up on the delete confirmation form.
if (empty($form_state['confirm_delete'])) {
$term = $form_state['controller']->getEntity($form_state);
$path = (isset($term->tid) ? drupal_container()->get('path.crud')->load(array('source' => 'taxonomy/term/' . $term->tid)) : array());
$path = ($term->id() ? Drupal::service('path.crud')->load(array('source' => 'taxonomy/term/' . $term->id())) : array());
if ($path === FALSE) {
$path = array();
}
$path += array(
'pid' => NULL,
'source' => isset($term->tid) ? 'taxonomy/term/' . $term->tid : NULL,
'source' => $term->id() ? 'taxonomy/term/' . $term->id() : NULL,
'alias' => '',
'langcode' => LANGUAGE_NOT_SPECIFIED,
);
......@@ -261,19 +261,46 @@ function path_form_taxonomy_term_form_alter(&$form, $form_state) {
}
}
/**
* Implements hook_data_type_info().
*/
function path_data_type_info() {
$info['path_field'] = array(
'label' => t('Path field item'),
'description' => t('An entity field containing a path alias and related data.'),
'class' => '\Drupal\path\Type\PathItem',
'list class' => '\Drupal\Core\Entity\Field\Type\Field',
);
return $info;
}
/**
* Implements hook_entity_field_info().
*/
function path_entity_field_info($entity_type) {
if ($entity_type === 'taxonomy_term') {
$info['definitions']['path'] = array(
'type' => 'path_field',
'label' => t('The path alias'),
'computed' => TRUE,
'list' => TRUE,
);
return $info;
}
}
/**
* Implements hook_taxonomy_term_insert().
*/
function path_taxonomy_term_insert(Term $term) {
if (isset($term->path)) {
$path = $term->path;
$path['alias'] = trim($path['alias']);
$term->path->alias = trim($term->path->alias);
// Only save a non-empty alias.
if (!empty($path['alias'])) {
if (!empty($term->path->alias)) {
// Ensure fields for programmatic executions.
$path['source'] = 'taxonomy/term/' . $term->tid;
$path['langcode'] = LANGUAGE_NOT_SPECIFIED;
drupal_container()->get('path.crud')->save($path['source'], $path['alias'], $path['langcode']);
$source = 'taxonomy/term/' . $term->id();
$langcode = LANGUAGE_NOT_SPECIFIED;
Drupal::service('path.crud')->save($source, $term->path->alias, $langcode);
}
}
}
......@@ -283,19 +310,18 @@ function path_taxonomy_term_insert(Term $term) {
*/
function path_taxonomy_term_update(Term $term) {
if (isset($term->path)) {
$path = $term->path;
$path['alias'] = trim($path['alias']);
$term->path->alias = trim($term->path->alias);
// Delete old alias if user erased it.
if (!empty($path['pid']) && empty($path['alias'])) {
drupal_container()->get('path.crud')->delete(array('pid' => $path['pid']));
if (!empty($term->path->pid) && empty($term->path->alias)) {
Drupal::service('path.crud')->delete(array('pid' => $term->path->pid));
}
// Only save a non-empty alias.
if (!empty($path['alias'])) {
$pid = (!empty($path['pid']) ? $path['pid'] : NULL);
if ($term->path->alias) {
$pid = (!empty($term->path->pid) ? $term->path->pid : NULL);
// Ensure fields for programmatic executions.
$path['source'] = 'taxonomy/term/' . $term->tid;
$path['langcode'] = LANGUAGE_NOT_SPECIFIED;
drupal_container()->get('path.crud')->save($path['source'], $path['alias'], $path['langcode'], $pid);
$source = 'taxonomy/term/' . $term->id();
$langcode = LANGUAGE_NOT_SPECIFIED;
Drupal::service('path.crud')->save($source, $term->path->alias, $langcode, $pid);
}
}
}
......@@ -305,7 +331,7 @@ function path_taxonomy_term_update(Term $term) {
*/
function path_taxonomy_term_delete(Term $term) {
// Delete all aliases associated with this term.
drupal_container()->get('path.crud')->delete(array('source' => 'taxonomy/term/' . $term->tid));
Drupal::service('path.crud')->delete(array('source' => 'taxonomy/term/' . $term->id()));
}
/**
......
......@@ -35,13 +35,13 @@ public static function getInfo() {
function testTaxonomyTermRdfaAttributes() {
$vocabulary = $this->createVocabulary();
$term = $this->createTerm($vocabulary);
$term_uri = url('taxonomy/term/' . $term->tid, array('absolute' => TRUE));
$term_uri = url('taxonomy/term/' . $term->id(), array('absolute' => TRUE));
// Parses the term's page and checks that the RDF output is correct.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$base_uri = url('<front>', array('absolute' => TRUE));
$parser->parse($graph, $this->drupalGet('taxonomy/term/' . $term->tid), 'rdfa', $base_uri);
$parser->parse($graph, $this->drupalGet('taxonomy/term/' . $term->id()), 'rdfa', $base_uri);
// Inspects RDF graph output.
// Term type.
......
......@@ -767,7 +767,7 @@ function rdf_preprocess_taxonomy_term(&$variables) {
$term_label_meta = array(
'#tag' => 'meta',