Commit a2224585 authored by webchick's avatar webchick

Issue #2074203 by cilefen, Wim Leers, Gábor Hojtsy: Add changed time tracking to menu links.

parent 8bce36ba
......@@ -182,6 +182,13 @@ public function getWeight() {
return (int) $this->get('weight')->value;
}
/**
* {@inheritdoc}
*/
public function getChangedTime() {
return $this->get('changed')->value;
}
/**
* Builds up the menu link plugin definition for this entity.
*
......@@ -386,6 +393,10 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->setLabel(t('Parent plugin ID'))
->setDescription(t('The ID of the parent menu link plugin, or empty string when at the top level of the hierarchy.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the menu link was last edited.'));
return $fields;
}
......
......@@ -7,12 +7,13 @@
namespace Drupal\menu_link_content;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Entity\ContentEntityInterface;
/**
* Defines an interface for custom menu links.
*/
interface MenuLinkContentInterface extends ContentEntityInterface {
interface MenuLinkContentInterface extends ContentEntityInterface, EntityChangedInterface {
/**
* Flags this instance as being wrapped in a menu link plugin instance.
......
......@@ -122,6 +122,28 @@ function assertMenuLinkParents($links, $expected_hierarchy) {
}
}
/**
* Assert that a link entity's created timestamp is set.
*/
public function testCreateLink() {
$options = array(
'menu_name' => 'menu_test',
'bundle' => 'menu_link_content',
);
$link = entity_create('menu_link_content', $options);
$link->save();
// Make sure the changed timestamp is set.
$this->assertEqual($link->getChangedTime(), REQUEST_TIME, 'Creating a menu link sets the "changed" timestamp.');
$options = array(
'title' => 'Test Link',
);
$link->setOptions($options);
$link->changed->value = REQUEST_TIME - 5;
$link->save();
// Make sure the changed timestamp is updated.
$this->assertEqual($link->getChangedTime(), REQUEST_TIME, 'Changing a menu link sets "changed" timestamp.');
}
/**
* Test automatic reparenting of menu links.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment