You are here

public function CourseObject::getOptionsSummary in Course 8.3

Same name and namespace in other branches
  1. 8.2 src/Entity/CourseObject.php \Drupal\course\Entity\CourseObject::getOptionsSummary()
  2. 3.x src/Entity/CourseObject.php \Drupal\course\Entity\CourseObject::getOptionsSummary()

Get core options summary.

Return value

array An associative array of summary keys and values.

Overrides CourseHandler::getOptionsSummary

4 calls to CourseObject::getOptionsSummary()
CourseObject::renderOptionsSummary in src/Entity/CourseObject.php
Get all course object implementations of getOptionsSummary().
CourseObjectNode::getOptionsSummary in modules/course_content/src/Course/Object/CourseObjectNode.php
Make the "Edit instance" link use a dialog.
CourseObjectQuiz::getOptionsSummary in modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuiz.php
Get core options summary.
CourseObjectWebform::getOptionsSummary in modules/course_webform/src/Plugin/course/CourseObject/CourseObjectWebform.php
Get core options summary.
3 methods override CourseObject::getOptionsSummary()
CourseObjectNode::getOptionsSummary in modules/course_content/src/Course/Object/CourseObjectNode.php
Make the "Edit instance" link use a dialog.
CourseObjectQuiz::getOptionsSummary in modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuiz.php
Get core options summary.
CourseObjectWebform::getOptionsSummary in modules/course_webform/src/Plugin/course/CourseObject/CourseObjectWebform.php
Get core options summary.

File

src/Entity/CourseObject.php, line 365

Class

CourseObject
Parent abstract base class of all course objects.

Namespace

Drupal\course\Entity

Code

public function getOptionsSummary() {
  $summary = parent::getOptionsSummary();

  // Get options.
  $options = $this
    ->getOptions();

  // Enabled.
  if ($options['enabled']) {
    $summary['enabled'] = t('Enabled');
  }
  else {
    $summary['enabled'] = '<span class="warning">' . t('Not enabled') . '</span>';
  }

  // Hidden.
  if (!$options['hidden']) {
    $summary['hidden'] = t('Visible in outline');
  }
  else {
    $summary['hidden'] = '<span class="warning">' . t('Not visible in outline') . '</span>';
  }

  // Required.
  if ($options['required']) {
    $summary['required'] = t('Completion required');
    if ($options['skippable']) {
      $summary['skippable'] = '<span class="warning">' . t('Skippable') . '</span>';
    }
  }
  else {
    $summary['required'] = '<span class="warning">' . t('Completion not required') . '</span>';
  }

  // Instance edit link.
  $editUrl = $this
    ->getEditUrl();
  if (!empty($editUrl)) {
    $text = t('Edit instance');
    $summary['instance'] = Link::fromTextAndUrl($text, $editUrl)
      ->toString();
  }
  elseif ($this
    ->isTemporary()) {
    $summary['instance'] = '<span class="warning">' . t('Save course to edit object') . '</span>';
  }

  // Instance view link.
  $viewUrl = $this
    ->getViewUrl();
  if (!empty($viewUrl)) {
    $text = t('View instance');
    $summary['instance_view'] = Link::fromTextAndUrl($text, $viewUrl)
      ->toString();
  }

  // Required.
  if (!empty($options['delete'])) {
    $dest = Url::fromRoute('course.object.restore', [
      'course' => $options['cid'],
      'course_object' => $this
        ->getId(),
    ], [
      'attributes' => [
        'class' => 'use-ajax',
      ],
    ]);
    $text = t('Object will be removed from outline');
    $restore_text = t('Restore this object to the course outline.');
    if ($options['delete_instance']) {
      $text = t('Object will be removed from outline, and related instance(s) will be deleted');
      $restore_text = t('Restore this object and related instance(s) to the course outline.');
    }
    $restore = Link::fromTextAndUrl(t('Restore'), $dest, $restore_text)
      ->toString();
    $summary['delete'] = '<span class="error">' . $text . '</span>';
    $summary['restore'] = $restore;
  }
  return $summary;
}