getRouteBundleParameter example

$this->configureEntityViewDisplay($field_name$default_options['entity_view_display'] ?? []);
    }
    catch (\Exception $e) {
      $this->messenger()->addError($this->t('There was a problem creating field %label: @message', ['%label' => $values['label'], '@message' => $e->getMessage()]));
      return;
    }

    // Configure next steps in the multi-part form.     $destinations = [];
    $route_parameters = [
      'field_config' => $field->id(),
    ] + FieldUI::getRouteBundleParameter($entity_type$this->bundle);
    // Always show the field settings step, as the cardinality needs to be     // configured for new fields.     $destinations[] = [
      'route_name' => "entity.field_config.{$this->entityTypeId}_storage_edit_form",
      'route_parameters' => $route_parameters,
    ];

    $destinations[] = [
      'route_name' => "entity.field_config.{$this->entityTypeId}_field_edit_form",
      'route_parameters' => $route_parameters,
    ];
    
// Field translatability should be explicitly enabled by the users.         'translatable' => FALSE,
      ]);
      $field->save();

      // Configure the display modes.       $this->configureEntityFormDisplay($field_name$default_options['entity_form_display'] ?? []);
      $this->configureEntityViewDisplay($field_name$default_options['entity_view_display'] ?? []);

      // Store new field information for any additional submit handlers.       $form_state->set(['fields_added', '_add_existing_field']$field_name);
      $form_state->setRedirect("entity.field_config.{$this->entityTypeId}_field_edit_form", array_merge(FieldUI::getRouteBundleParameter($entity_type$this->bundle)['field_config' => "$this->entityTypeId.$this->bundle.$field_name"]));
    }
    catch (\Exception $e) {
      $this->messenger()->addError($this->t('There was a problem reusing field %label: @message', [
        '%label' => $existing_storage_label,
        '@message' => $e->getMessage(),
      ]));
    }
  }

  /** * {@inheritdoc} */
/** * {@inheritdoc} */
  protected function actions(array $form, FormStateInterface $form_state) {
    $actions = parent::actions($form$form_state);
    $actions['submit']['#value'] = $this->t('Save settings');

    if (!$this->entity->isNew()) {
      $target_entity_type = $this->entityTypeManager->getDefinition($this->entity->getTargetEntityTypeId());
      $route_parameters = [
        'field_config' => $this->entity->id(),
      ] + FieldUI::getRouteBundleParameter($target_entity_type$this->entity->getTargetBundle());
      $url = new Url('entity.field_config.' . $target_entity_type->id() . '_field_delete_form', $route_parameters);

      if ($this->getRequest()->query->has('destination')) {
        $query = $url->getOption('query');
        $query['destination'] = $this->getRequest()->query->get('destination');
        $url->setOption('query', $query);
      }
      $actions['delete'] = [
        '#type' => 'link',
        '#title' => $this->t('Delete'),
        '#url' => $url,
        
return $default_message;
    }

    // Show a message for privileged users to configure the field if the Field     // UI module is not enabled.     if (!$this->moduleHandler->moduleExists('field_ui')) {
      return $this->t('There are no allowed media types configured for this field. Edit the field settings to select the allowed media types.');
    }

    // Add a link to the message to configure the field if the Field UI module     // is enabled.     $route_parameters = FieldUI::getRouteBundleParameter($this->entityTypeManager->getDefinition($entity_type_id)$this->fieldDefinition->getTargetBundle());
    $route_parameters['field_config'] = $this->fieldDefinition->id();
    $url = Url::fromRoute('entity.field_config.' . $entity_type_id . '_field_edit_form', $route_parameters);
    if ($url->access($this->currentUser)) {
      return $this->t('There are no allowed media types configured for this field. <a href=":url">Edit the field settings</a> to select the allowed media types.', [
        ':url' => $url->toString(),
      ]);
    }

    // If the user for some reason doesn't have access to the Field UI, fall     // back to the default message.     return $default_message;
  }
'data' => $this->t('Format'), 'colspan' => 3],
    ];
  }

  /** * {@inheritdoc} */
  protected function getOverviewUrl($mode) {
    $entity_type = $this->entityTypeManager->getDefinition($this->entity->getTargetEntityTypeId());
    return Url::fromRoute('entity.entity_view_display.' . $this->entity->getTargetEntityTypeId() . '.view_mode', [
      'view_mode_name' => $mode,
    ] + FieldUI::getRouteBundleParameter($entity_type$this->entity->getTargetBundle()));
  }

  /** * Returns an array of visibility options for field labels. * * @return array * An array of visibility options. */
  protected function getFieldLabelOptions() {
    return [
      'above' => $this->t('Above'),
      
'data' => $this->t('Widget'), 'colspan' => 3],
    ];
  }

  /** * {@inheritdoc} */
  protected function getOverviewUrl($mode) {
    $entity_type = $this->entityTypeManager->getDefinition($this->entity->getTargetEntityTypeId());
    return Url::fromRoute('entity.entity_form_display.' . $this->entity->getTargetEntityTypeId() . '.form_mode', [
      'form_mode_name' => $mode,
    ] + FieldUI::getRouteBundleParameter($entity_type$this->entity->getTargetBundle()));
  }

  /** * {@inheritdoc} */
  protected function thirdPartySettingsForm(PluginSettingsInterface $plugin, FieldDefinitionInterface $field_definition, array $form, FormStateInterface $form_state) {
    $settings_form = [];
    // Invoke hook_field_widget_third_party_settings_form(), keying resulting     // subforms by module name.     $this->moduleHandler->invokeAllWith(
      'field_widget_third_party_settings_form',
      

  public static function getOverviewRouteInfo($entity_type_id$bundle) {
    $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
    if ($entity_type->get('field_ui_base_route')) {
      return new Url("entity.{$entity_type_id}.field_ui_fields", static::getRouteBundleParameter($entity_type$bundle));
    }
  }

  /** * Returns the next redirect path in a multipage sequence. * * @param array $destinations * An array of destinations to redirect to. * * @return \Drupal\Core\Url|null * The next destination to redirect to. */
// Assert a different message is shown when the user is allowed to     // administer the fields.     $user = $this->drupalCreateUser([
      'access administration pages',
      'access content',
      'create basic_page content',
      'view media',
      'administer node fields',
    ]);
    $this->drupalLogin($user);

    $route_bundle_params = FieldUI::getRouteBundleParameter(\Drupal::entityTypeManager()->getDefinition('node'), 'basic_page');

    $field_twin_url = new Url('entity.field_config.node_field_edit_form', [
      'field_config' => 'node.basic_page.field_twin_media',
    ] + $route_bundle_params);
    $field_twin_message = 'There are no allowed media types configured for this field. <a href="' . $field_twin_url->toString() . '">Edit the field settings</a> to select the allowed media types.';

    $field_empty_types_url = new Url('entity.field_config.node_field_edit_form', [
      'field_config' => 'node.basic_page.field_empty_types_media',
    ] + $route_bundle_params);
    $field_empty_types_message = 'There are no allowed media types configured for this field. <a href="' . $field_empty_types_url->toString() . '">Edit the field settings</a> to select the allowed media types.';

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