Problem/Motivation

When I'm trying to extend the module's ViewsFiltersSummary ViewsArea plugin just to override some functions, for example, buildFilterSummaryItem() - this doesn't work, the parent function is called instead of the function in the overridden class.

Steps to reproduce

1. Extend the class like this:

class MUViewsFiltersSummary extends ViewsFiltersSummary {
...
}

2. Override a function like this:

  protected function buildFilterSummaryItem(
    string $id,
    string $label,
    string $value,
    string|int|null $value_raw = NULL,
  ): array {
    $item = parent::buildFilterSummaryItem($id, $label, $value, $value_raw);
    $item['value'] = 'Test';
    return $item;

3. Add this plugin to a view area, and see that this doesn't work.

Proposed resolution

The issue is that the original plugin class uses "self" instead of "static" in the method create():

  /**
   * {@inheritdoc}
   */
  public static function create(
    ContainerInterface $container,
    array $configuration,
    $plugin_id,
    $plugin_definition,
  ) {
    return new self(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('string_translation'),
      $container->get('entity_type.manager'),
      $container->get('entity_type.bundle.info'),
      $container->get('logger.factory'),
      $container->get('language_manager')
    );
  }

Changing "self" to "static" resolves the issue.

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

murz created an issue. See original summary.

murz’s picture

Status: Active » Needs review

Created a MR with the fix, please review.

  • mably committed 0d02cf24 on 3.x authored by murz
    [#3548577] fix: Unable to use parent functions in the plugins that...
mably’s picture

Status: Needs review » Fixed

Thanks for the fix!

If there is anything we can add to this module, feel free to share.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

murz’s picture

Such a quick merge, thanks! Updated the contribution record.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.