Commit c7908ced authored by Claudiu Cristea's avatar Claudiu Cristea
Browse files

Issue #3287573 by claudiu.cristea, Project Update Bot: Automated Drupal 10 compatibility fixes

parent b8978e16
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -17,13 +17,9 @@
    }
  ],
  "support": {
    "issues": "http://drupal.org/project/file_uri",
    "irc": "irc://irc.freenode.org/drupal-contribute",
    "source": "http://cgit.drupalcode.org/file_uri"
    "issues": "https://www.drupal.org/project/issues/file_url",
    "source": "https://git.drupalcode.org/project/file_url"
  },
  "license": "GPL-2.0+",
  "minimum-stability": "dev",
  "require": {
    "drupal/core": "^8 || ^9"
  }
  "minimum-stability": "dev"
}
+2 −2
Original line number Diff line number Diff line
@@ -2,6 +2,6 @@ name: File URL
type: module
description: Reference both local and remote files by URI.
package: Custom
core_version_requirement: ^8 || ^9
core_version_requirement: ^8 || ^9 || ^10
dependencies:
  - drupal:file (>=8.7.x)
  - drupal:file
+2 −2
Original line number Diff line number Diff line
@@ -3,5 +3,5 @@ remote_url:
  js:
    js/remote_url.js: {}
  dependencies:
    - core/jquery
    - core/jquery.once
    - core/drupal
    - core/once
+10 −10
Original line number Diff line number Diff line
@@ -3,11 +3,7 @@
 * Improves the remote URL text field.
 */

(function ($, Drupal) {

  'use strict';

  // @todo Add remote URL client validation.
(function (Drupal) {

  /**
   * Attach behaviors to the file URL auto add URL.
@@ -20,14 +16,18 @@
   *   Detaches triggers for the remote URL addition.
   */
  Drupal.behaviors.fileUrlRemoteUrlAdd = {
    attach: function (context) {
      $(context).find('input[data-drupal-file-url-remote]').once('auto-remote-url-add').on('change.autoRemoteUrlAdd', Drupal.file.triggerUploadButton);
    attach(context) {
      once("auto-remote-url-add", "input[data-drupal-file-url-remote]", context).forEach((element) => {
        element.addEventListener('change', Drupal.file.triggerUploadButton);
      });
    },
    detach: function (context, setting, trigger) {
    detach(context, setting, trigger) {
      if (trigger === 'unload') {
        $(context).find('input[data-drupal-file-url-remote]').removeOnce('auto-remote-url-add').off('.autoRemoteUrlAdd');
        once.remove("auto-remote-url-add", "input[data-drupal-file-url-remote]").forEach((element) => {
          element.removeEventListener('change', Drupal.file.triggerUploadButton);
        });
      }
    }
  };

})(jQuery, Drupal);
})(Drupal);
+61 −9
Original line number Diff line number Diff line
@@ -2,10 +2,13 @@

namespace Drupal\file_url\Plugin\Field\FieldFormatter;

use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\File\FileUrlGeneratorInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase;
use Drupal\file_url\FileUrlHandler;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Plugin implementation of the 'file_default' formatter.
@@ -14,16 +17,64 @@ use Drupal\file_url\FileUrlHandler;
 *   id = "file_url_default",
 *   label = @Translation("Generic file"),
 *   field_types = {
 *     "file_url"
 *   }
 *     "file_url",
 *   },
 * )
 */
class FileUrlFormatter extends FileFormatterBase {

  /**
   * The file URL generator service.
   *
   * @var \Drupal\Core\File\FileUrlGeneratorInterface
   */
  protected FileUrlGeneratorInterface $fileUrlGenerator;

  /**
   * Constructs a new formatter plugin instance.
   *
   * @param string $plugin_id
   *   The plugin_id for the formatter.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
   *   The definition of the field to which the formatter is associated.
   * @param array $settings
   *   The formatter settings.
   * @param string $label
   *   The formatter label display setting.
   * @param string $view_mode
   *   The view mode.
   * @param array $third_party_settings
   *   Any third party settings.
   * @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator
   *   The file URL generator service.
   */
  public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, FileUrlGeneratorInterface $file_url_generator) {
    parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
    $this->fileUrlGenerator = $file_url_generator;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self {
    return new static(
      $plugin_id,
      $plugin_definition,
      $configuration['field_definition'],
      $configuration['settings'],
      $configuration['label'],
      $configuration['view_mode'],
      $configuration['third_party_settings'],
      $container->get('file_url_generator')
    );
  }

  /**
   * {@inheritdoc}
   */
  public static function defaultSettings() {
  public static function defaultSettings(): array {
    return [
      'mode' => 'link',
    ] + parent::defaultSettings();
@@ -32,7 +83,7 @@ class FileUrlFormatter extends FileFormatterBase {
  /**
   * {@inheritdoc}
   */
  public function settingsForm(array $form, FormStateInterface $form_state) {
  public function settingsForm(array $form, FormStateInterface $form_state): array {
    $elements = parent::settingsForm($form, $form_state);

    $elements['mode'] = [
@@ -51,7 +102,7 @@ class FileUrlFormatter extends FileFormatterBase {
  /**
   * {@inheritdoc}
   */
  public function settingsSummary() {
  public function settingsSummary(): array {
    $summary = parent::settingsSummary();

    switch ($this->getSetting('mode')) {
@@ -69,15 +120,16 @@ class FileUrlFormatter extends FileFormatterBase {
  /**
   * {@inheritdoc}
   */
  public function viewElements(FieldItemListInterface $items, $langcode) {
  public function viewElements(FieldItemListInterface $items, $langcode): array {
    $elements = [];

    /** @var \Drupal\Core\Field\EntityReferenceFieldItemListInterface $items */
    foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
      $item = $file->_referringItem;
      if ($this->getSetting('mode') === 'plain') {
        $elements['delta'] = [
          $elements[$delta] = [
            '#markup' => file_url_transform_relative(file_create_url($file->getFileUri())),
            '#markup' => $this->fileUrlGenerator->generateString($file->getFileUri()),
            '#cache' => [
              'tags' => $file->getCacheTags(),
            ],
@@ -107,7 +159,7 @@ class FileUrlFormatter extends FileFormatterBase {
      // Allow showing the full URI as tip.
      // @todo Probably the UX/UI team should decide if the full URL should be
      //   permanently displayed when showing distributions.
      $elements[$delta]['#attributes']['title'] = file_create_url($file->getFileUri());
      $elements[$delta]['#attributes']['title'] = $this->fileUrlGenerator->generateAbsoluteString($file->getFileUri());
    }

    return $elements;
@@ -116,7 +168,7 @@ class FileUrlFormatter extends FileFormatterBase {
  /**
   * {@inheritdoc}
   */
  public function prepareView(array $entities_items) {
  public function prepareView(array $entities_items): void {
    // Collect entity IDs to load. For performance, we want to use a single
    // "multiple entity load" to load all the entities for the multiple
    // "entity reference item lists" being displayed. We thus cannot use
Loading