You are here

public function CourseObjectWebform::getWarnings in Course 3.x

Same name and namespace in other branches
  1. 8.3 modules/course_webform/src/Plugin/course/CourseObject/CourseObjectWebform.php \Drupal\course_webform\Plugin\course\CourseObject\CourseObjectWebform::getWarnings()
  2. 8.2 modules/course_webform/src/Plugin/course/CourseObject/CourseObjectWebform.php \Drupal\course_webform\Plugin\course\CourseObject\CourseObjectWebform::getWarnings()

Return a list of warning strings about this handler.

For example, if a user adds a quiz to a course with no questions, trigger a message.

Overrides CourseHandler::getWarnings

File

modules/course_webform/src/Plugin/course/CourseObject/CourseObjectWebform.php, line 41

Class

CourseObjectWebform
Plugin annotation @CourseObject( id = "webform", label = "Webform", handlers = { "fulfillment" = "\Drupal\course_webform\Plugin\course\CourseObject\CourseObjectWebformFulfillment" } )

Namespace

Drupal\course_webform\Plugin\course\CourseObject

Code

public function getWarnings() {
  $warnings = parent::getWarnings();
  $webform = Webform::load($this
    ->getInstanceId());
  if ($this
    ->getInstanceId() && !$webform
    ->getElementsDecoded()) {
    $link = Link::createFromRoute(t('add questions'), 'entity.webform.edit_form', [
      'webform' => $webform
        ->id(),
    ])
      ->toString();
    $warnings[] = t('The Webform has no questions. Please @link.', array(
      '@link' => $link,
    ));
  }
  return $warnings;
}