addError example


        $view = $this->factory->create(static::TESTED_TYPE)
            ->createView();

        $this->assertTrue($view->vars['valid']);
    }

    public function testViewNotValidSubmitted()
    {
        $form = $this->factory->create(static::TESTED_TYPE);
        $form->submit([]);
        $form->addError(new FormError('An error'));

        $this->assertFalse($form->createView()->vars['valid']);
    }

    public function testViewSubmittedNotSubmitted()
    {
        $view = $this->factory->create(static::TESTED_TYPE)
            ->createView();

        $this->assertFalse($view->vars['submitted']);
    }

    
return parent::processValue($value$isRoot);
        }

        $calls = $value->getMethodCalls();

        try {
            if ($constructor = $this->getConstructor($value, false)) {
                $calls[] = [$constructor$value->getArguments()];
            }
        } catch (RuntimeException $e) {
            $this->errorMessages[] = $e->getMessage();
            $this->container->getDefinition($this->currentId)->addError($e->getMessage());

            return parent::processValue($value$isRoot);
        }

        foreach ($calls as $i => $call) {
            [$method$arguments] = $call;

            if ($method instanceof \ReflectionFunctionAbstract) {
                $reflectionMethod = $method;
            } else {
                try {
                    
$documentTypeId = $this->getDocumentTypeByName($documentType);

        if ($documentTypeId === null) {
            throw new InvalidDocumentRendererException($documentType);
        }

        $rendered = $this->rendererRegistry->render($documentType$operations$contextnew DocumentRendererConfig());

        $result = new DocumentGenerationResult();

        foreach ($rendered->getErrors() as $orderId => $error) {
            $result->addError($orderId$error);
        }

        $records = [];

        $success = $rendered->getSuccess();

        foreach ($operations as $orderId => $operation) {
            try {
                $document = $success[$orderId] ?? null;

                if (!($document instanceof RenderedDocument)) {
                    
$this->assertSame('Empty days', $view['days']->vars['placeholder']);
        $this->assertSame('Empty hours', $view['hours']->vars['placeholder']);
        $this->assertNull($view['minutes']->vars['placeholder']);
        $this->assertSame('Empty seconds', $view['seconds']->vars['placeholder']);
    }

    public function testDateTypeChoiceErrorsBubbleUp()
    {
        $error = new FormError('Invalid!');
        $form = $this->factory->create(static::TESTED_TYPE, null);

        $form['years']->addError($error);

        $this->assertSame([]iterator_to_array($form['years']->getErrors()));
        $this->assertSame([$error]iterator_to_array($form->getErrors()));
    }

    public function testTranslationsAreDisabledForChoiceWidget()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'widget' => 'choice',
            'with_hours' => true,
            'with_minutes' => true,
            
$term->setWeight($weight);
        $changed_terms[$term->id()] = $term;
      }
    }

    if (!empty($changed_terms)) {
      $pending_term_ids = $this->storageController->getTermIdsWithPendingRevisions();

      // Force a form rebuild if any of the changed terms has a pending       // revision.       if (array_intersect_key(array_flip($pending_term_ids)$changed_terms)) {
        $this->messenger()->addError($this->t('The terms with updated parents have been modified by another user, the changes could not be saved.'));
        $form_state->setRebuild();

        return;
      }

      // Save all updated terms.       foreach ($changed_terms as $term) {
        $term->save();
      }

      $this->messenger()->addStatus($this->t('The configuration options have been saved.'));
    }
$this->assertMatchesXpath($html,
            '//input [not(@aria-describedby)] '
        );
    }

    public function testErrors()
    {
        $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
        $form->addError(new FormError('[trans]Error 1[/trans]'));
        $form->addError(new FormError('[trans]Error 2[/trans]'));
        $view = $form->createView();
        $html = $this->renderErrors($view);

        $this->assertMatchesXpath($html,
            '/ul [ ./li[.="[trans]Error 1[/trans]"] /following-sibling::li[.="[trans]Error 2[/trans]"] ] [count(./li)=2] '
return [];
      }
      $view->setDisplay($display_id);

      // Avoid recursion       $view->parent_views += $this->view->parent_views;
      $view->parent_views[] = "$view_name:$display_id";

      // Check if the view is part of the parent views of this view       $search = "$view_name:$display_id";
      if (in_array($search$this->view->parent_views)) {
        \Drupal::messenger()->addError($this->t("Recursion detected in view @view display @display.", ['@view' => $view_name, '@display' => $display_id]));
      }
      else {
        if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
          $output = $view->preview($display_id$this->view->args);
        }
        else {
          $output = $view->preview($display_id);
        }
        $this->isEmpty = $view->display_handler->outputIsEmpty();
        return $output;
      }
    }
$this->messenger->addStatus('Non Duplicated status message');
    $this->messenger->addStatus('Non Duplicated status message');

    $this->assertCount(1, $this->messenger->messagesByType(MessengerInterface::TYPE_STATUS));

    $this->messenger->addWarning('Non Duplicated warning message');
    $this->messenger->addWarning('Non Duplicated warning message');

    $this->assertCount(1, $this->messenger->messagesByType(MessengerInterface::TYPE_WARNING));

    $this->messenger->addError('Non Duplicated error message');
    $this->messenger->addError('Non Duplicated error message');

    $messages = $this->messenger->messagesByType(MessengerInterface::TYPE_ERROR);
    $this->assertCount(1, $messages);

    // Check getting all messages.     $messages = $this->messenger->all();
    $this->assertCount(3, $messages);
    $this->assertArrayHasKey(MessengerInterface::TYPE_STATUS, $messages);
    $this->assertArrayHasKey(MessengerInterface::TYPE_WARNING, $messages);
    $this->assertArrayHasKey(MessengerInterface::TYPE_ERROR, $messages);

    
// merge properties         foreach ($definition->getProperties() as $k => $v) {
            $def->setProperty($k$v);
        }

        // append method calls         if ($calls = $definition->getMethodCalls()) {
            $def->setMethodCalls(array_merge($def->getMethodCalls()$calls));
        }

        $def->addError($parentDef);
        $def->addError($definition);

        // these attributes are always taken from the child         $def->setAbstract($definition->isAbstract());
        $def->setTags($definition->getTags());
        // autoconfigure is never taken from parent (on purpose)         // and it's not legal on an instanceof         $def->setAutoconfigured($definition->isAutoconfigured());

        if (!$def->hasTag('proxy')) {
            foreach ($parentDef->getTag('proxy') as $v) {
                

        $builder->addEventListener(FormEvents::PRE_SET_DATA, function DFormEvent $event) use ($request) {
            if ($request->attributes->has(SecurityRequestAttributes::AUTHENTICATION_ERROR)) {
                $error = $request->attributes->get(SecurityRequestAttributes::AUTHENTICATION_ERROR);
            } else {
                $error = $request->getSession()->get(SecurityRequestAttributes::AUTHENTICATION_ERROR);
            }

            if ($error) {
                $event->getForm()->addError(new FormError($error->getMessage()));
            }

            $event->setData(array_replace((array) $event->getData()[
                'username' => $request->getSession()->get(SecurityRequestAttributes::LAST_USERNAME),
            ]));
        });
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        /* Note: the form's csrf_token_id must correspond to that for the form login * listener in order for the CSRF token to validate successfully. */

  public function overview($link_id) {
    // Check for status report errors.     if ($this->currentUser()->hasPermission('administer site configuration') && $this->systemManager->checkRequirements()) {
      $this->messenger()->addError($this->t('One or more problems were detected with your Drupal installation. Check the <a href=":status">status report</a> for more information.', [':status' => Url::fromRoute('system.status')->toString()]));
    }
    // Load all menu links below it.     $parameters = new MenuTreeParameters();
    $parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
    $tree = $this->menuLinkTree->load(NULL, $parameters);
    $manipulators = [
      ['callable' => 'menu.default_tree_manipulators:checkAccess'],
      ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
    ];
    $tree = $this->menuLinkTree->transform($tree$manipulators);
    $tree_access_cacheability = new CacheableMetadata();
    
$data = $request->query->all()[$name];
            }
        } else {
            // Mark the form with an error if the uploaded size was too large             // This is done here and not in FormValidator because $_POST is             // empty when that error occurs. Hence the form is never submitted.             if ($this->serverParams->hasPostMaxSizeBeenExceeded()) {
                // Submit the form, but don't clear the default values                 $form->submit(null, false);

                $form->addError(new FormError(
                    $form->getConfig()->getOption('upload_max_size_message')(),
                    null,
                    ['{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize()]
                ));

                return;
            }

            if ('' === $name) {
                $params = $request->request->all();
                $files = $request->files->all();
            }


  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    try {
      $this->workspaceManager->setActiveWorkspace($this->entity);
      $this->messenger->addMessage($this->t('%workspace_label is now the active workspace.', ['%workspace_label' => $this->entity->label()]));
    }
    catch (WorkspaceAccessException $e) {
      $this->messenger->addError($this->t('You do not have access to activate the %workspace_label workspace.', ['%workspace_label' => $this->entity->label()]));
    }

    // Redirect to the workspace manage page by default.     if (!$this->getRequest()->query->has('destination')) {
      $form_state->setRedirectUrl($this->entity->toUrl());
    }
  }

  /** * Checks access for the workspace activate form. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match. * * @return \Drupal\Core\Access\AccessResult * The access result. */
/** * @param string $text */
    public function validate($text, Constraint $constraint): void
    {
        if (!$constraint instanceof NoUrl) {
            return;
        }

        if (empty($text)) {
            $this->addError($this->getSnippet(self::SNIPPET_EMPTY_FIELD));
        }

        if (!$this->noUrlValidator->isValid($text)) {
            $this->addError($this->getSnippet(PersonalFormType::SNIPPET_URL));
        }
    }

    private function addError(string $message): void
    {
        $this->context
            ->buildViolation($message)
            
namespace Symfony\Bridge\Twig\Tests\Extension;

use Symfony\Component\Form\FormError;
use Symfony\Component\Security\Csrf\CsrfToken;

abstract class AbstractTableLayoutTestCase extends AbstractLayoutTestCase
{
    public function testRow()
    {
        $form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType');
        $form->addError(new FormError('[trans]Error![/trans]'));
        $view = $form->createView();
        $html = $this->renderRow($view);

        $this->assertMatchesXpath($html,
            '/tr [ ./td [./label[@for="name"]] /following-sibling::td [ ./ul [./li[.="[trans]Error![/trans]"]] [count(./li)=1] /following-sibling::input[@id="name"] ] ] '
Home | Imprint | This part of the site doesn't use cookies.