Created on 23 February 2025, 4 months ago

In VotingApiLazyLoader:

  public function buildForm($plugin_id, $entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, $settings): array {
    $definitions = $this->widgetManager->getDefinitions();

    /** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */
    $entity = $this->entityTypeManager->getStorage($entity_type)->load($entity_id);

    /** @var \Drupal\votingapi_widgets\Plugin\VotingApiWidgetInterface $plugin */
    $plugin = $this->widgetManager->createInstance($plugin_id, $definitions[$plugin_id]);

    $fieldDefinition = $entity->{$field_name}->getFieldDefinition();
    if (empty($plugin) || empty($entity) || !$entity->hasField($field_name)) {
      return [];
    }
    return $plugin->buildForm($entity_type, $entity_bundle, $entity_id, $vote_type, $field_name, unserialize($settings));
  }

As you can see, $fieldDefinition is never used. This line was added by commit e7d284ad back in 2016, and initially the variable was used.

The "if" statement following the declaration of $fieldDefinition was added by #2905540: Error: Call to a member function getFieldDefinition() on null β†’ back in 2018 -this "if" statement was intended to prevent an error that happened when $fieldDefinition was used and was null.

Then in #2973112: Remove unused code for read only setting. β†’ , also in 2018, the use of $fieldDefinition was removed, but the declaration of $fieldDefinition was not removed and the "if" statement which protected the use was not removed either.

As a result all of this is dead code.

And when we remove this, you will see that the declaration of $entity is no longer needed either, because it is never used. And that means we don't need to be injecting the EntityTypeManager anymore either.

Lots of dead code!

πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024