You are here

public function WorkspaceReferenceItem::applyDefaultValue in Multiversion 8

Applies the default value.

Parameters

bool $notify: (optional) Whether to notify the parent object of the change. Defaults to TRUE. If a property is updated from a parent object, set it to FALSE to avoid being notified again.

Return value

$this Returns itself to allow for chaining.

Overrides Map::applyDefaultValue

File

src/Plugin/Field/FieldType/WorkspaceReferenceItem.php, line 20

Class

WorkspaceReferenceItem
Plugin annotation @FieldType( id = "workspace_reference", label = @Translation("Workspace reference"), description = @Translation("This field stores a reference to the workspace the entity belongs to."), no_ui = TRUE )

Namespace

Drupal\multiversion\Plugin\Field\FieldType

Code

public function applyDefaultValue($notify = TRUE) {

  /** @var \Drupal\multiversion\Entity\WorkspaceInterface $workspace */
  $workspace = \Drupal::service('workspace.manager')
    ->getActiveWorkspace();
  $this
    ->setValue([
    'target_id' => $workspace
      ->id(),
  ], $notify);
  return $this;
}