getUrlWithReplacedCsrfTokenPlaceholder example

$dynamic_plugin_config['drupalMedia']['previewURL'] = Url::fromRoute('media.filter.preview')
      ->setRouteParameter('filter_format', $editor->getFilterFormat()->id())
      ->toString(TRUE)
      ->getGeneratedUrl();
    [$element_style_configuration$toolbar_configuration,
    ] = self::configureViewModes($editor);

    $dynamic_plugin_config['drupalElementStyles']['viewMode'] = $element_style_configuration;
    if ($this->getConfiguration()['allow_view_mode_override']) {
      $dynamic_plugin_config['drupalMedia']['toolbar'][] = $toolbar_configuration;
    }
    $dynamic_plugin_config['drupalMedia']['metadataUrl'] = self::getUrlWithReplacedCsrfTokenPlaceholder(
      Url::fromRoute('ckeditor5.media_entity_metadata')
        ->setRouteParameter('editor', $editor->id())
    );
    $dynamic_plugin_config['drupalMedia']['previewCsrfToken'] = \Drupal::csrfToken()->get('X-Drupal-MediaPreview-CSRF-Token');
    return $dynamic_plugin_config;
  }

  /** * {@inheritdoc} */
  public function getElementsSubset(): array {
    
use CKEditor5PluginConfigurableTrait;
  use DynamicPluginConfigWithCsrfTokenUrlTrait;

  /** * {@inheritdoc} */
  public function getDynamicPluginConfig(array $static_plugin_config, EditorInterface $editor): array {
    $config = $static_plugin_config;
    if ($editor->getImageUploadSettings()['status'] === TRUE) {
      $config += [
        'drupalImageUpload' => [
          'uploadUrl' => self::getUrlWithReplacedCsrfTokenPlaceholder(
            Url::fromRoute('ckeditor5.upload_image')
              ->setRouteParameter('editor', $editor->getFilterFormat()->id())
          ),
          'withCredentials' => TRUE,
          'headers' => ['Accept' => 'application/json', 'text/javascript'],
        ],
      ];
    }
    return $config;
  }

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