You are here

public function OpignoModuleResultActions::render in Opigno module 3.x

Same name and namespace in other branches
  1. 8 src/Plugin/views/field/OpignoModuleResultActions.php \Drupal\opigno_module\Plugin\views\field\OpignoModuleResultActions::render()

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides FieldPluginBase::render

File

src/Plugin/views/field/OpignoModuleResultActions.php, line 128

Class

OpignoModuleResultActions
A handler to provide a field that is completely custom by the administrator.

Namespace

Drupal\opigno_module\Plugin\views\field

Code

public function render(ResultRow $values) {
  $entity = $this
    ->getEntityTranslation($this
    ->getEntity($values), $values);
  $operations = $this->entityTypeManager
    ->getListBuilder($entity
    ->getEntityTypeId())
    ->getOperations($entity);
  unset($operations["edit"], $operations["devel"]);

  /** @var \Drupal\opigno_module\Entity\OpignoActivity $activities */
  $activities = $values->_relationship_entities["module"]
    ->getModuleActivities();
  $activities = array_column((array) $activities, 'type');
  $manually_scored_activities = [
    'opigno_file_upload',
    'opigno_long_answer',
  ];
  $correct_activity = !empty(array_intersect($manually_scored_activities, $activities));
  $module_score_parameters = [
    'opigno_module' => $values->opigno_module_field_data_user_module_status_id,
    'user_module_status' => $values->id,
  ];
  if ($correct_activity) {
    $operations['score'] = [
      'title' => $this
        ->t('Score'),
      'weight' => 20,
      'url' => Url::fromRoute('opigno_module.module_result_form', $module_score_parameters),
    ];
  }
  $build = [
    '#type' => 'operations',
    '#links' => $operations,
  ];
  return $build;
}