Skip to content
Snippets Groups Projects
Commit 504486ad authored by project update bot's avatar project update bot Committed by Lucas Hedding
Browse files

Issue #3430613 by heddn: Automated Drupal 11 compatibility fixes for fixed_text_link_formatter

parent d9fd6905
Branches
Tags
1 merge request!4Automated Project Update Bot fixes
Pipeline #354739 canceled
......@@ -51,49 +51,12 @@ include:
# variables:
# SKIP_ESLINT: '1'
###################################################################################
#
# *
# /(
# ((((,
# /(((((((
# ((((((((((*
# ,(((((((((((((((
# ,(((((((((((((((((((
# ((((((((((((((((((((((((*
# *(((((((((((((((((((((((((((((
# ((((((((((((((((((((((((((((((((((*
# *(((((((((((((((((( .((((((((((((((((((
# ((((((((((((((((((. /(((((((((((((((((*
# /((((((((((((((((( .(((((((((((((((((,
# ,(((((((((((((((((( ((((((((((((((((((
# .(((((((((((((((((((( .(((((((((((((((((
# ((((((((((((((((((((((( ((((((((((((((((/
# (((((((((((((((((((((((((((/ ,(((((((((((((((*
# .((((((((((((((/ /(((((((((((((. ,(((((((((((((((
# *(((((((((((((( ,(((((((((((((/ *((((((((((((((.
# ((((((((((((((, /(((((((((((((. ((((((((((((((,
# (((((((((((((/ ,(((((((((((((* ,(((((((((((((,
# *((((((((((((( .((((((((((((((( ,(((((((((((((
# ((((((((((((/ /((((((((((((((((((. ,((((((((((((/
# ((((((((((((( *(((((((((((((((((((((((* *((((((((((((
# ((((((((((((( ,(((((((((((((..((((((((((((( *((((((((((((
# ((((((((((((, /((((((((((((* /((((((((((((/ ((((((((((((
# ((((((((((((( /((((((((((((/ (((((((((((((* ((((((((((((
# (((((((((((((/ /(((((((((((( ,((((((((((((, *((((((((((((
# (((((((((((((( *(((((((((((/ *((((((((((((. ((((((((((((/
# *((((((((((((((((((((((((((, /(((((((((((((((((((((((((
# ((((((((((((((((((((((((( ((((((((((((((((((((((((,
# .(((((((((((((((((((((((/ ,(((((((((((((((((((((((
# ((((((((((((((((((((((/ ,(((((((((((((((((((((/
# *((((((((((((((((((((( (((((((((((((((((((((,
# ,(((((((((((((((((((((, ((((((((((((((((((((/
# ,(((((((((((((((((((((* /((((((((((((((((((((
# ((((((((((((((((((((((, ,/((((((((((((((((((((,
# ,(((((((((((((((((((((((((((((((((((((((((((((((((((
# .(((((((((((((((((((((((((((((((((((((((((((((
# .((((((((((((((((((((((((((((((((((((,.
# .,(((((((((((((((((((((((((.
# Start custom overrides.
# Based on https://git.drupalcode.org/project/keycdn/-/blob/8.x-1.x/.gitlab-ci.yml
#
###################################################################################
variables:
# Convenient, and we have no secrets.
_SHOW_ENVIRONMENT_VARIABLES: 1
......@@ -4,6 +4,6 @@
"description": "Fixed text link formatter.",
"license": "GPL-2.0-or-later",
"require": {
"drupal/core": "^9.3 || ^10"
"drupal/core": "^9.3 || ^10 || ^11"
}
}
name: Fixed Text Link Formatter
type: module
description: Formats a link field with a configurable fixed link text.
core_version_requirement: ^9.3 || ^10
core_version_requirement: ^9.3 || ^10 || ^11
dependencies:
- drupal:link
......@@ -3,11 +3,13 @@
namespace Drupal\fixed_text_link_formatter\Plugin\Field\FieldFormatter;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\File\FileUrlGeneratorInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Plugin implementation of the 'file_url_plain' formatter.
......@@ -22,15 +24,44 @@ use Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase;
*/
class FixedTextFileUrl extends FileFormatterBase {
public function __construct(
$plugin_id,
$plugin_definition,
FieldDefinitionInterface $field_definition,
array $settings,
$label,
$view_mode,
array $third_party_settings,
protected readonly FileUrlGeneratorInterface $fileUrlGenerator,
) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
}
/**
* {@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() {
return [
'link_text' => 'Download',
'link_class' => '',
'open_in_new_window' => FALSE,
] + parent::defaultSettings();
'link_text' => 'Download',
'link_class' => '',
'open_in_new_window' => FALSE,
] + parent::defaultSettings();
}
/**
......@@ -77,7 +108,7 @@ class FixedTextFileUrl extends FileFormatterBase {
}
/**
* @return boolean
* @return bool
*/
private function openLinkInNewWindow() {
return $this->getSettings()['open_in_new_window'];
......@@ -104,7 +135,7 @@ class FixedTextFileUrl extends FileFormatterBase {
/** @var \Drupal\file\Entity\File $file */
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $file) {
$text = $this->getLinkText();
$url = \Drupal::service('file_url_generator')->generate($file->getFileUri());
$url = $this->fileUrlGenerator->generate($file->getFileUri());
$link = Link::fromTextAndUrl($text, $url);
$build = $link->toRenderable();
......
......@@ -23,12 +23,12 @@ class FixedTextLink extends LinkFormatter {
* {@inheritdoc}
*/
public static function defaultSettings() {
return array(
return [
'trim_length' => '',
'link_text' => 'View website',
'link_class' => '',
'allow_override' => FALSE,
) + parent::defaultSettings();
] + parent::defaultSettings();
}
/**
......
......@@ -2,10 +2,10 @@
namespace Drupal\Tests\fixed_text_link_formatter\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\link\LinkItemInterface;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the correct function of the Fixed Text Link formatter.
......@@ -49,6 +49,9 @@ class FixedTextLinkTest extends BrowserTestBase {
*/
private $linkFieldName;
/**
* {@inheritdoc}
*/
public function setUp(): void {
parent::setUp();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment