Thanks to visit codestin.com
Credit goes to git.drupalcode.org

Commit 04fad283 authored by Joshua Sedler's avatar Joshua Sedler 🤸🏼 Committed by Julian Pustkuchen
Browse files

Issue #3334757 by Grevil: Code style and phpstan fixes

parent 4e6f970c
Loading
Loading
Loading
Loading
+26 −25
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Routing\RedirectDestinationTrait;
use Drupal\Core\Routing\RedirectDestination;
use Drupal\Core\Url;
use Drupal\views\Plugin\views\area\TokenizeAreaPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -23,8 +23,6 @@ use Symfony\Component\Routing\RequestContext;
 */
class Link extends TokenizeAreaPluginBase {

  use RedirectDestinationTrait;

  /**
   * The language manager.
   *
@@ -46,6 +44,13 @@ class Link extends TokenizeAreaPluginBase {
   */
  protected $context;

  /**
   * A helper object for handling redirect destinations.
   *
   * @var \Drupal\Core\Routing\RedirectDestination
   */
  protected $destination;

  /**
   * Constructs a new Entity instance.
   *
@@ -61,12 +66,15 @@ class Link extends TokenizeAreaPluginBase {
   *   The access manager.
   * @param \Symfony\Component\Routing\RequestContext $context
   *   The request context.
   * @param \Drupal\Core\Routing\RedirectDestination $destination
   *   A helper object for handling redirect destinations.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager, AccessManagerInterface $access_manager, RequestContext $context) {
  public function __construct(array $configuration, $plugin_id, $plugin_definition, LanguageManagerInterface $language_manager, AccessManagerInterface $access_manager, RequestContext $context, RedirectDestination $destination) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->languageManager = $language_manager;
    $this->accessManager = $access_manager;
    $this->context = $context;
    $this->destination = $destination;
  }

  /**
@@ -92,7 +100,8 @@ class Link extends TokenizeAreaPluginBase {
      $plugin_definition,
      $container->get('language_manager'),
      $container->get('access_manager'),
      $container->get('router.request_context')
      $container->get('router.request_context'),
      $container->get('redirect.destination')
    );
  }

@@ -266,7 +275,6 @@ class Link extends TokenizeAreaPluginBase {
    $options = $form_state->getValue('options');

    // @todo validate like \Drupal\link\Plugin\Field\FieldWidget\LinkWidget

    $form_state->setValue('options', $options);
  }

@@ -278,13 +286,12 @@ class Link extends TokenizeAreaPluginBase {
  public function render($empty = FALSE) {
    // Note: Method adapted from the renderAsLinkmethod from
    // Drupal\views\Plugin\views\field\FieldPluginBase.
    // @phpstan-ignore-next-line
    if ($empty && empty($this->options['empty'])) {
      return [];
    }

    $options = [
      'absolute' => !empty($this->options['absolute']) ? TRUE : FALSE, // @phpstan-ignore-line
      'absolute' => !empty($this->options['absolute']) ? TRUE : FALSE,
      'alias' => FALSE,
      'entity' => NULL,
      'entity_type' => NULL,
@@ -325,14 +332,12 @@ class Link extends TokenizeAreaPluginBase {
      // 'http://www.example.com'.
      // Only do this when flag for external has been set, $path doesn't contain
      // a scheme and $path doesn't have a leading /.
      // @phpstan-ignore-next-line
      if ($this->options['external'] && !parse_url($path, PHP_URL_SCHEME) && strpos($path, '/') !== 0) {
        // There is no scheme, add the default 'http://' to the $path.
        $path = "http://" . $path;
      }
    }

    // @phpstan-ignore-next-line
    if (!parse_url($path, PHP_URL_SCHEME)) {
      $url = Url::fromUserInput('/' . ltrim($path, '/'));
    }
@@ -344,11 +349,11 @@ class Link extends TokenizeAreaPluginBase {

    $path = $url->setOptions($options)->toUriString();

    // @phpstan-ignore-next-line
    if (!empty($this->options['path_case']) && $this->options['path_case'] != 'none' && !$url->isRouted()) {
      $path = str_replace($this->options['path'], $this->caseTransform($this->options['path'], $this->options['path_case']), $path);
    }
    // @phpstan-ignore-next-line

    // @todo Where is "$url_info" defined?
    if (!empty($url_info['replace_spaces'])) {
      $path = str_replace(' ', '-', $path);
    }
@@ -357,14 +362,12 @@ class Link extends TokenizeAreaPluginBase {
    $url_parts = UrlHelper::parse($path);

    // Seriously malformed URLs may return FALSE or empty arrays.
    // @phpstan-ignore-next-line
    if (empty($url_parts)) {
      return $this->options['link_text'];
    }

    // If the path is empty do not build a link around the given text and return
    // it as is.
    // @phpstan-ignore-next-line
    if (empty($url_parts['path']) && empty($url_parts['fragment']) && empty($url_parts['url'])) {
      return $this->options['link_text'];
    }
@@ -411,7 +414,6 @@ class Link extends TokenizeAreaPluginBase {
      $options['attributes']['class'] = [$class];
    }

    // @phpstan-ignore-next-line
    if (!empty($this->options['rel']) && $rel = $this->tokenizeValue($this->options['rel'])) {
      $options['attributes']['rel'] = $rel;
    }
@@ -421,9 +423,8 @@ class Link extends TokenizeAreaPluginBase {
      $options['attributes']['target'] = $target;
    }

    // @phpstan-ignore-next-line
    if (!empty($this->options['destination'])) {
      $options['query'] += \Drupal::destination()->getAsArray();
      $options['query'] += $this->destination->getAsArray();
    }

    if ($this->languageManager->isMultilingual() && $this->options['language'] !== '**auto**') {
+0 −1
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ name: 'Views Test Link Area'
type: module
description: 'Provides default views for tests.'
package: Testing
version: VERSION
core_version_requirement: ^9 || ^10
dependencies:
  - drupal:views
+4 −4
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ class LinkAreaTest extends ViewsKernelTestBase {
    'entity_test',
    'user',
    'views_linkarea',
    'views_test_linkarea'
    'views_test_linkarea',
  ];

  /**
@@ -122,7 +122,7 @@ class LinkAreaTest extends ViewsKernelTestBase {
        'link_text' => 'SSSSSS',
      ],
      'SSSSSS',
      '/'
      '/',
    ];
    $data[] = [
      [
@@ -130,7 +130,7 @@ class LinkAreaTest extends ViewsKernelTestBase {
        'link_text' => '<b>Pass</b>',
      ],
      'Pass',
      '/user/password'
      '/user/password',
    ];
    $data[] = [
      [
@@ -138,7 +138,7 @@ class LinkAreaTest extends ViewsKernelTestBase {
        'link_text' => '<b>Pass</b>',
      ],
      'Pass',
      '/entity_test/1'
      '/entity_test/1',
    ];
    return $data;
  }
+0 −1
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ name: 'Views Link Area'
description: 'A Views area plugin to allow links as headers and footers for views.'
type: module
core_version_requirement: ^9 || ^10
version: VERSION
package: 'Views'
dependencies:
  - drupal:views