You are here

protected function ContentEntitySourcePluginUi::buildPublishStateElement in Translation Management Tool 8

Build a publish state element.

Parameters

\Drupal\tmgmt\JobItemInterface $item: The job item.

\Drupal\Core\Entity\EntityPublishedInterface $entity: The source publishable entity.

Return value

array A publish state form element.

1 call to ContentEntitySourcePluginUi::buildPublishStateElement()
ContentEntitySourcePluginUi::reviewForm in sources/content/src/ContentEntitySourcePluginUi.php
Form callback for the job item review form.

File

sources/content/src/ContentEntitySourcePluginUi.php, line 617

Class

ContentEntitySourcePluginUi
Content entity source plugin UI.

Namespace

Drupal\tmgmt_content

Code

protected function buildPublishStateElement(JobItemInterface $item, EntityPublishedInterface $entity) {
  $element = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Translation publish status'),
    '#tree' => TRUE,
  ];
  $published = $item
    ->getData([
    '#published',
  ], 0);
  $default_value = isset($published[0]) ? $published[0] : $entity
    ->isPublished();
  $published_title = $this
    ->t('Published');
  $published_field = $entity
    ->getEntityType()
    ->getKey('published');
  if ($entity instanceof FieldableEntityInterface && $entity
    ->hasField($published_field)) {
    $published_field_definition = $entity
      ->get($published_field)
      ->getFieldDefinition();
    $published_title = $published_field_definition
      ->getConfig($entity
      ->bundle())
      ->getLabel();
    if (!$published_field_definition
      ->isTranslatable()) {
      $published_title = $this
        ->t('@published_title (all languages)', [
        '@published_title' => $published_title,
      ]);
    }
  }
  $element['published'] = [
    '#type' => 'checkbox',
    '#default_value' => $default_value,
    '#title' => $published_title,
  ];
  return $element;
}