addStatus example


  public function execute($entity = NULL) {
    if (empty($this->configuration['node'])) {
      $this->configuration['node'] = $entity;
    }
    $message = $this->token->replace($this->configuration['message']$this->configuration);
    $build = [
      '#markup' => $message,
    ];

    // @todo Fix in https://www.drupal.org/node/2577827     $this->messenger->addStatus($this->renderer->renderPlain($build));
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return [
      'message' => '',
    ];
  }

  
$writer->open();
      $writer->writeItem($item);
      $writer->writeItems($reader);
      $writer->close();

      $response = new BinaryFileResponse($uri);
      $response->setContentDisposition('attachment', $filename);
      $form_state->setResponse($response);
    }
    else {
      $this->messenger()->addStatus($this->t('Nothing to export.'));
    }
  }

}
if (parse_url($link, PHP_URL_SCHEME) === NULL && $this->pathValidator->isValid($link)) {
      $shortcut = $this->entityTypeManager()->getStorage('shortcut')->create([
        'title' => $name,
        'shortcut_set' => $shortcut_set->id(),
        'link' => [
          'uri' => 'internal:/' . $link,
        ],
      ]);

      try {
        $shortcut->save();
        $this->messenger()->addStatus($this->t('Added a shortcut for %title.', ['%title' => $shortcut->label()]));
      }
      catch (\Exception $e) {
        $this->messenger()->addError($this->t('Unable to add a shortcut for %title.', ['%title' => $shortcut->label()]));
      }

      return $this->redirect('<front>');
    }

    throw new AccessDeniedHttpException();
  }

}
return $form;
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    parent::save($form$form_state);

    $t_args = ['%language' => $this->entity->label(), '%langcode' => $this->entity->id()];
    $this->logger('language')->notice('The %language (%langcode) language has been created.', $t_args);
    $this->messenger()->addStatus($this->t('The language %language has been created and can now be used.', $t_args));

    if ($this->moduleHandler->moduleExists('block')) {
      // Tell the user they have the option to add a language switcher block       // to their theme so they can switch between the languages.       $this->messenger()->addStatus($this->t('Use one of the language switcher blocks to allow site visitors to switch between languages. You can enable these blocks on the <a href=":block-admin">block administration page</a>.', [':block-admin' => Url::fromRoute('block.admin_display')->toString()]));
    }
    $form_state->setRedirectUrl($this->entity->toUrl('collection'));
  }

  /** * {@inheritdoc} */
$form['#title'] = $this->entity->label();
    $form = parent::form($form$form_state);
    $form['roles']['#default_value'] = array_keys(filter_get_roles_by_format($this->entity));
    return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form$form_state);
    $this->messenger()->addStatus($this->t('The text format %format has been updated.', ['%format' => $this->entity->label()]));
    return $this->entity;
  }

}
$form_state->set('user', $account);
    $form_state->setValue('uid', $account->id());

    $this->logger('user')->info('New user: %name %email.', ['%name' => $form_state->getValue('name'), '%email' => '<' . $form_state->getValue('mail') . '>', 'type' => $account->toLink($this->t('Edit'), 'edit-form')->toString()]);

    // Add plain text password into user account to generate mail tokens.     $account->password = $pass;

    // New administrative account without notification.     if ($admin && !$notify) {
      $this->messenger()->addStatus($this->t('Created a new user account for <a href=":url">%name</a>. No email has been sent.', [':url' => $account->toUrl()->toString(), '%name' => $account->getAccountName()]));
    }
    // No email verification required; log in user immediately.     elseif (!$admin && !\Drupal::config('user.settings')->get('verify_mail') && $account->isActive()) {
      _user_mail_notify('register_no_approval_required', $account);
      user_login_finalize($account);
      $this->messenger()->addStatus($this->t('Registration successful. You are now logged in.'));
      $form_state->setRedirect('<front>');
    }
    // No administrator approval required.     elseif ($account->isActive() || $notify) {
      if (!$account->getEmail() && $notify) {
        

  public function save(array $form, FormStateInterface $form_state) {
    $entity = $this->entity;

    // Prevent leading and trailing spaces in role names.     $entity->set('label', trim($entity->label()));
    $status = $entity->save();

    $edit_link = $this->entity->toLink($this->t('Edit'), 'edit-form')->toString();
    if ($status == SAVED_UPDATED) {
      $this->messenger()->addStatus($this->t('Role %label has been updated.', ['%label' => $entity->label()]));
      $this->logger('user')->info('Role %label has been updated.', ['%label' => $entity->label(), 'link' => $edit_link]);
    }
    else {
      $this->messenger()->addStatus($this->t('Role %label has been added.', ['%label' => $entity->label()]));
      $this->logger('user')->info('Role %label has been added.', ['%label' => $entity->label(), 'link' => $edit_link]);
    }
    $form_state->setRedirect('entity.user_role.collection');
  }

}
return $form;
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    $workflow = $this->entity;
    $return = $workflow->save();
    if (empty($workflow->getTypePlugin()->getStates())) {
      $this->messenger()->addStatus($this->t('Created the %label Workflow. In order for the workflow to be enabled there needs to be at least one state.', [
        '%label' => $workflow->label(),
      ]));
      $form_state->setRedirectUrl($workflow->toUrl('add-state-form'));
    }
    else {
      $this->messenger()->addStatus($this->t('Created the %label Workflow.', [
        '%label' => $workflow->label(),
      ]));
      $form_state->setRedirectUrl($workflow->toUrl('edit-form'));
    }
    return $return;
  }
if (str_contains($machine_name, 'duplicate')) {
      return TRUE;
    }

    return FALSE;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->messenger()->addStatus('The form_test_machine_name_validation_form form has been submitted successfully.');
  }

}
'image_mapping_type' => 'image_style',
              'image_mapping' => $image_style_mapping['image_style'],
            ];
            $responsive_image_style->addImageStyleMapping($breakpoint_id$multiplier$mapping);
          }
        }
      }
    }
    $responsive_image_style->save();

    $this->logger('responsive_image')->notice('Responsive image style @label saved.', ['@label' => $responsive_image_style->label()]);
    $this->messenger()->addStatus($this->t('Responsive image style %label saved.', ['%label' => $responsive_image_style->label()]));

    // Redirect to edit form after creating a new responsive image style or     // after selecting another breakpoint group.     if (!$responsive_image_style->hasImageStyleMappings()) {
      $form_state->setRedirect(
        'entity.responsive_image_style.edit_form',
        ['responsive_image_style' => $responsive_image_style->id()]
      );
    }
    else {
      $form_state->setRedirectUrl($this->entity->toUrl('collection'));
    }
return ['#markup' => $this->t('Content to test main content fallback')];
  }

  /** * Tests setting messages and removing one before it is displayed. * * @return string * Empty string, we just test the setting of messages. */
  public function messengerServiceTest() {
    // Set two messages.     $this->messenger->addStatus('First message (removed).');
    $this->messenger->addStatus($this->t('Second message with <em>markup!</em> (not removed).'));
    $messages = $this->messenger->deleteByType('status');
    // Remove the first.     unset($messages[0]);

    foreach ($messages as $message) {
      $this->messenger->addStatus($message);
    }

    // Duplicate message check.     $this->messenger->addStatus('Non Duplicated message');
    

  public function __construct(StateInterface $state) {
    $this->state = $state;
  }

  /** * A simple kernel listener method. */
  public function onKernelRequestTest(RequestEvent $event) {
    \Drupal::messenger()->addStatus(t('The service_provider_test event subscriber fired!'));
  }

  /** * Flags the response in case a rebuild indicator is used. */
  public function onKernelResponseTest(ResponseEvent $event) {
    if ($this->container->hasParameter('container_rebuild_indicator')) {
      $event->getResponse()->headers->set('container_rebuild_indicator', $this->container->getParameter('container_rebuild_indicator'));
    }
    if ($this->container->hasParameter('container_rebuild_test_parameter')) {
      $event->getResponse()->headers->set('container_rebuild_test_parameter', $this->container->getParameter('container_rebuild_test_parameter'));
    }
$this->messenger = \Drupal::service('messenger');
  }

  /** * @covers ::addStatus * @covers ::deleteByType * @covers ::messagesByType */
  public function testRemoveSingleMessage() {

    // Set two messages.     $this->messenger->addStatus('First message (removed).');
    $this->messenger->addStatus('Second message with <em>markup!</em> (not removed).');
    $messages = $this->messenger->deleteByType(MessengerInterface::TYPE_STATUS);
    // Remove the first.     unset($messages[0]);

    // Re-add the second.     foreach ($messages as $message) {
      $this->messenger->addStatus($message);
    }

    // Check we only have the second one.

    }
    return $operations;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form$form_state);

    $this->messenger->addStatus($this->t('The role settings have been updated.'));
  }

}
/** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $subformState = SubformState::createForSubform($form['entity_bundle']$form$form_state);
    $this->condition->submitConfigurationForm($form['entity_bundle']$subformState);
    $subformState = SubformState::createForSubform($form['current_theme']$form$form_state);

    $this->conditionCurrentTheme->submitConfigurationForm($form['current_theme']$subformState);
    $config = $this->condition->getConfig();
    foreach ($config['bundles'] as $bundle) {
      \Drupal::messenger()->addStatus('Bundle: ' . $bundle);
    }

    $article = Node::load(1);
    $this->condition->setContextValue('node', $article);
    if ($this->condition->execute()) {
      \Drupal::messenger()->addStatus($this->t('Executed successfully.'));
    }
    if ($this->conditionCurrentTheme->execute()) {
      \Drupal::messenger()->addStatus($this->conditionCurrentTheme->summary());
    }
  }

}
Home | Imprint | This part of the site doesn't use cookies.