You are here

public function AdminCommentForm::render in Commerce Core 8.2

Render the area.

Parameters

bool $empty: (optional) Indicator if view result is empty or not. Defaults to FALSE.

Return value

array In any case we need a valid Drupal render array to return.

Overrides AreaPluginBase::render

File

modules/log/src/Plugin/views/area/AdminCommentForm.php, line 95

Class

AdminCommentForm
Defines a log comment form.

Namespace

Drupal\commerce_log\Plugin\views\area

Code

public function render($empty = FALSE) {
  if ($empty && empty($this->options['empty'])) {
    return [];
  }
  $source_entity_id = NULL;
  $source_entity_type = NULL;
  foreach ($this->view->argument as $argument) {
    if ($argument
      ->getField() === 'commerce_log.source_entity_id') {
      $source_entity_id = $argument
        ->getValue();
    }
    elseif ($argument
      ->getField() === 'commerce_log.source_entity_type') {
      $source_entity_type = $argument
        ->getValue();
    }
  }
  if ($source_entity_id === NULL || $source_entity_type === NULL) {
    return [];
  }
  $log_template_id = $source_entity_type . '_admin_comment';
  if (!$this->logTemplateManager
    ->hasDefinition($log_template_id)) {
    return [];
  }
  $permission = $this->currentUser
    ->hasPermission("add commerce_log {$source_entity_type} admin comment");
  if (!$permission) {
    return [];
  }
  $storage = $this->entityTypeManager
    ->getStorage($source_entity_type);
  $entity = $storage
    ->load($source_entity_id);
  if ($entity) {
    $form = $this->formBuilder
      ->getForm(LogCommentForm::class, $source_entity_type, $source_entity_id, $log_template_id);
    $form['log_comment']['comment']['#description'] = $this
      ->t('Your comment will only be visible to users who have access to the activity log.');
    return $form;
  }
  return [];
}