RevisionsProperty.php in Multiversion 8.2
File
src/Field/RevisionsProperty.php
View source
<?php
namespace Drupal\multiversion\Field;
use Drupal\Core\TypedData\TypedData;
class RevisionsProperty extends TypedData {
protected $value = [];
public function getValue($langcode = NULL) {
$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 {
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;
}
}