getNextDestination example



  /** * @covers ::getNextDestination */
  public function testGetNextDestination() {
    $destinations = ['admin', 'admin/content'];
    $expected_uri = 'base:admin';
    $expected_query = [
      'destinations' => ['admin/content'],
    ];
    $actual = FieldUI::getNextDestination($destinations);
    $this->assertSame($expected_uri$actual->getUri());
    $this->assertSame($expected_query$actual->getOption('query'));
  }

  /** * @covers ::getNextDestination */
  public function testGetNextDestinationEmpty() {
    $destinations = [];
    $actual = FieldUI::getNextDestination($destinations);
    $this->assertNull($actual);
  }


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

    $this->messenger()->addStatus($this->t('Saved %label configuration.', ['%label' => $this->entity->getLabel()]));

    $request = $this->getRequest();
    if (($destinations = $request->query->all('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) {
      $request->query->remove('destinations');
      $form_state->setRedirectUrl($next_destination);
    }
    else {
      $form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($this->entity->getTargetEntityTypeId()$this->entity->getTargetBundle()));
    }
  }

  /** * The _title_callback for the field settings form. * * @param \Drupal\field\FieldConfigInterface $field_config * The field. * * @return string * The label of the field. */


  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    $field_label = $form_state->get('field_config')->label();
    try {
      $this->entity->save();
      $this->messenger()->addStatus($this->t('Updated field %label field settings.', ['%label' => $field_label]));
      $request = $this->getRequest();
      if (($destinations = $request->query->all('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) {
        $request->query->remove('destinations');
        $form_state->setRedirectUrl($next_destination);
      }
      else {
        $form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($form_state->get('entity_type_id')$form_state->get('bundle')));
      }
    }
    catch (\Exception $e) {
      $this->messenger()->addStatus($this->t('Attempt to update field %label failed: %message.', ['%label' => $field_label, '%message' => $e->getMessage()]));
    }
  }

  
$destinations[] = [
      'route_name' => "entity.field_config.{$this->entityTypeId}_field_edit_form",
      'route_parameters' => $route_parameters,
    ];
    $destinations[] = [
      'route_name' => "entity.{$this->entityTypeId}.field_ui_fields",
      'route_parameters' => $route_parameters,
    ];
    $destination = $this->getDestinationArray();
    $destinations[] = $destination['destination'];
    $form_state->setRedirectUrl(
      FieldUI::getNextDestination($destinations)
    );

    // Store new field information for any additional submit handlers.     $form_state->set(['fields_added', '_add_new_field']$field_name);

    $this->messenger()->addMessage($this->t('Your settings have been saved.'));
  }

  /** * Get default options from preconfigured options for a new field. * * @param string $field_name * The machine name of the field. * @param string $preset_key * A key in the preconfigured options array for the field. * * @return array * An array of settings with keys 'field_storage_config', 'field_config', * 'entity_form_display', and 'entity_view_display'. * * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException * * @see \Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface::getPreconfiguredOptions() */
Home | Imprint | This part of the site doesn't use cookies.