form example


    public function submitForm(string $button, array $fieldValues = [], string $method = 'POST', array $serverParameters = []): Crawler
    {
        $crawler = $this->crawler ?? throw new BadMethodCallException(sprintf('The "request()" method must be called before "%s()".', __METHOD__));
        $buttonNode = $crawler->selectButton($button);

        if (0 === $buttonNode->count()) {
            throw new InvalidArgumentException(sprintf('There is no button with "%s" as its content, id, value or name.', $button));
        }

        $form = $buttonNode->form($fieldValues$method);

        return $this->submit($form[]$serverParameters);
    }

    /** * Calls a URI. * * @param string $method The request method * @param string $uri The URI to fetch * @param array $parameters The Request parameters * @param array $files The files * @param array $server The server parameters (HTTP headers are referenced with an HTTP_ prefix as PHP does) * @param string $content The raw body data * @param bool $changeHistory Whether to update the history or not (only used internally for back(), forward(), and reload()) */
$container->get('entity_type.bundle.info'),
      $container->get('datetime.time')
    );
  }

  /** * {@inheritdoc} */
  public function form(array $form, FormStateInterface $form_state) {
    $user = $this->currentUser();
    $message = $this->entity;
    $form = parent::form($form$form_state);
    $form['#attributes']['class'][] = 'contact-form';

    if (!empty($message->preview)) {
      $form['preview'] = [
        '#theme_wrappers' => ['container__preview'],
        '#attributes' => ['class' => ['preview']],
      ];
      $form['preview']['message'] = $this->entityTypeManager->getViewBuilder('contact_message')->view($message, 'full');
    }

    $form['name'] = [
      

        '#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vocabulary->id()),
      ];
    }
    // Set the hierarchy to "multiple parents" by default. This simplifies the     // vocabulary form and standardizes the term form.     $form['hierarchy'] = [
      '#type' => 'value',
      '#value' => '0',
    ];

    $form = parent::form($form$form_state);
    return $this->protectBundleIdElement($form);
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $vocabulary = $this->entity;

    // Prevent leading and trailing spaces in vocabulary names.     $vocabulary->set('name', trim($vocabulary->label()));

    
/** * {@inheritdoc} */
  protected function getEditableConfigNames() {
    return ['contact.settings'];
  }

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

    $contact_form = $this->entity;
    $default_form = $this->config('contact.settings')->get('default_form');

    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Label'),
      '#maxlength' => 255,
      '#default_value' => $contact_form->label(),
      '#description' => $this->t("Example: 'website feedback' or 'product information'."),
      '#required' => TRUE,
    ];
    if (!$menu->isNew() || $menu->isLocked()) {
      // Form API supports constructing and validating self-contained sections       // within forms, but does not allow handling the form section's submission       // equally separated yet. Therefore, we use a $form_state key to point to       // the parents of the form section.       // @see self::submitOverviewForm()       $form_state->set('menu_overview_form_parents', ['links']);
      $form['links'] = [];
      $form['links'] = $this->buildOverviewForm($form['links']$form_state);
    }

    return parent::form($form$form_state);
  }

  /** * Returns whether a menu name already exists. * * @param string $value * The name of the menu. * * @return bool * Returns TRUE if the menu already exists, FALSE otherwise. */
  
return $constraints;
  }

  /** * {@inheritdoc} */
  public function defaultValuesForm(array &$form, FormStateInterface $form_state) {
    if (empty($this->getFieldDefinition()->getDefaultValueCallback())) {
      if ($widget = $this->defaultValueWidget($form_state)) {
        // Place the input in a separate place in the submitted values tree.         $element = ['#parents' => ['default_value_input']];
        $element += $widget->form($this$element$form_state);

        return $element;
      }
      else {
        return ['#markup' => $this->t('No widget available for: %type.', ['%type' => $this->getFieldDefinition()->getType()])];
      }
    }
  }

  /** * {@inheritdoc} */
/** * {@inheritdoc} */
  public function form(FieldItemListInterface $items, array &$form, FormStateInterface $form_state$get_delta = NULL) {
    // Load the items for form rebuilds from the field state.     $field_state = static::getWidgetState($form['#parents']$this->fieldDefinition->getName()$form_state);
    if (isset($field_state['items'])) {
      usort($field_state['items'][SortArray::class, 'sortByWeightElement']);
      $items->setValue($field_state['items']);
    }

    return parent::form($items$form$form_state$get_delta);
  }

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

    // Update reference to 'items' stored during add or remove to take into     // account changes to values like 'weight' etc.     // @see Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget::addItems

        $instance = apply_filters( 'widget_form_callback', $instance$this );

        $return = null;

        if ( false !== $instance ) {
            $return = $this->form( $instance );

            /** * Fires at the end of the widget control form. * * Use this hook to add extra fields to the widget form. The hook * is only fired if the value passed to the 'widget_form_callback' * hook is not false. * * Note: If the widget has no form, the text echoed from the default * form method can be hidden using CSS. * * @since 2.8.0 * * @param WP_Widget $widget The widget instance (passed by reference). * @param null $return Return null if new fields are added. * @param array $instance An array of the widget's settings. */
/** * Form controller for the test config edit forms. * * @internal */
class ConfigTestForm extends EntityForm {

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

    $entity = $this->entity;
    $form['label'] = [
      '#type' => 'textfield',
      '#title' => 'Label',
      '#default_value' => $entity->label(),
      '#required' => TRUE,
    ];
    $form['id'] = [
      '#type' => 'machine_name',
      '#default_value' => $entity->id(),
      
class FilterFormatEditForm extends FilterFormatFormBase {

  /** * {@inheritdoc} */
  public function form(array $form, FormStateInterface $form_state) {
    if (!$this->entity->status()) {
      throw new NotFoundHttpException();
    }

    $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;
  }

  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('plugin.manager.workflows.type')
    );
  }

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

    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    $workflow = $this->entity;
    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Label'),
      '#maxlength' => 255,
      '#default_value' => $workflow->label(),
      '#required' => TRUE,
    ];

    
namespace Symfony\Bundle\SecurityBundle\Tests\Functional;

class FormLoginTest extends AbstractWebTestCase
{
    /** * @dataProvider provideClientOptions */
    public function testFormLogin(array $options)
    {
        $client = $this->createClient($options);

        $form = $client->request('GET', '/login')->selectButton('login')->form();
        $form['_username'] = 'johannes';
        $form['_password'] = 'test';
        $client->submit($form);

        $this->assertRedirect($client->getResponse(), '/profile');

        $text = $client->followRedirect()->text(null, true);
        $this->assertStringContainsString('Hello johannes!', $text);
        $this->assertStringContainsString('You\'re browsing to path "/profile".', $text);
    }

    
/** * {@inheritdoc} */
  protected function prepareEntity() {
    // Do not prepare the entity while it is being added.   }

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

    $form['#title'] = $this->t('Duplicate of @label', ['@label' => $this->entity->label()]);

    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('View name'),
      '#required' => TRUE,
      '#size' => 32,
      '#maxlength' => 255,
      '#default_value' => $this->t('Duplicate of @label', ['@label' => $this->entity->label()]),
    ];
    
'#options' => TimeZoneFormHelper::getOptionsListByRegion($account->id() != $user->id()),
      '#description' => $this->t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'),
    ];

    // If not set or selected yet, detect timezone for the current user only.     $user_input = $form_state->getUserInput();
    if (!$account->getTimezone() && $account->id() == $user->id() && empty($user_input['timezone'])) {
      $form['timezone']['#attached']['library'][] = 'core/drupal.timezone';
      $form['timezone']['timezone']['#attributes'] = ['class' => ['timezone-detect']];
    }

    return parent::form($form$form_state);
  }

  /** * {@inheritdoc} */
  public static function trustedCallbacks() {
    return ['alterPreferredLangcodeDescription'];
  }

  /** * Alters the preferred language widget description. * * @param array $element * The preferred language form element. * * @return array * The preferred language form element. */

  public function __construct(EntityTypeManagerInterface $entity_type_manager, LoggerInterface $logger, CommentManagerInterface $comment_manager) {
    $this->entityTypeManager = $entity_type_manager;
    $this->logger = $logger;
    $this->commentManager = $comment_manager;
  }

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

    $comment_type = $this->entity;

    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Label'),
      '#maxlength' => 255,
      '#default_value' => $comment_type->label(),
      '#required' => TRUE,
    ];
    $form['id'] = [
      
Home | Imprint | This part of the site doesn't use cookies.