- Issue created by @tr
Automatically closed - issue fixed for 2 weeks with no activity.
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!
Active
2.0
Code
Automatically closed - issue fixed for 2 weeks with no activity.