You are here

class QuizAddQuestionAction in Quiz 8.5

Same name and namespace in other branches
  1. 8.6 src/Plugin/Action/QuizAddQuestionAction.php \Drupal\quiz\Plugin\Action\QuizAddQuestionAction
  2. 6.x src/Plugin/Action/QuizAddQuestionAction.php \Drupal\quiz\Plugin\Action\QuizAddQuestionAction

Action description.

Plugin annotation


@Action(
  id = "quiz_add_question_to_quiz",
  label = @Translation("Add questions to quiz"),
  type = "quiz_question"
)

Hierarchy

Expanded class hierarchy of QuizAddQuestionAction

File

src/Plugin/Action/QuizAddQuestionAction.php, line 19

Namespace

Drupal\quiz\Plugin\Action
View source
class QuizAddQuestionAction extends ViewsBulkOperationsActionBase {
  use StringTranslationTrait;

  /**
   * {@inheritdoc}
   */
  public function execute($entity = NULL) {

    /* @var $url Drupal\Core\Url */
    $url = $this->context['redirect_url'];
    $qid = $url
      ->getRouteParameters()['quiz'];
    $quiz = \Drupal::entityTypeManager()
      ->getStorage('quiz')
      ->loadRevision($qid);
    $quiz
      ->addQuestion($entity);
    return $this
      ->t('Added question to quiz.');
  }

  /**
   * {@inheritdoc}
   */
  public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
QuizAddQuestionAction::access public function
QuizAddQuestionAction::execute public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.