public function RevisionsProperty::getValue in Multiversion 8
Same name and namespace in other branches
- 8.2 src/Field/RevisionsProperty.php \Drupal\multiversion\Field\RevisionsProperty::getValue()
Gets the data value.
Return value
mixed The data value.
Overrides TypedData::getValue
File
- src/
Field/ RevisionsProperty.php, line 20
Class
- RevisionsProperty
- The 'revisions' property for revision token fields.
Namespace
Drupal\multiversion\FieldCode
public function getValue($langcode = NULL) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this
->getRoot()
->getValue();
$workspace = isset($entity->workspace) ? $entity->workspace->entity : null;
$branch = \Drupal::service('multiversion.entity_index.factory')
->get('multiversion.entity_index.rev.tree', $workspace)
->getDefaultBranch($entity
->uuid());
$values = [];
if (empty($branch) && !$entity->_rev->is_stub && !$entity
->isNew()) {
list($i, $hash) = explode('-', $entity->_rev->value);
$values = [
$hash,
];
}
else {
// We want children first and parent last.
foreach (array_reverse($branch) as $rev => $status) {
list($i, $hash) = explode('-', $rev);
$values[] = $hash;
}
}
if (empty($this->value)) {
$this->value = [];
}
$count_value = count($this->value);
$count_branch = count($values);
if ($count_value == 0 && $count_branch == 0) {
return [];
}
elseif ($count_value == 0 && $count_branch > 0 || count(array_intersect($values, $this->value)) == $count_value) {
$this->value = $values;
}
return $this->value;
}