- Issue created by @lazzyvn
- ๐ฎ๐ณIndia abhishek_virasat
abhishek_gupta1 โ made their first commit to this issueโs fork.
- last update
7 months ago 15 pass - Status changed to Needs review
7 months ago 10:10am 15 May 2024 - ๐ฎ๐ณIndia abhishek_virasat
@lazzyvn, I have verified above patch. issue has fixed. working for . also I created MR easy to merge. please review it once
- Status changed to Needs work
7 months ago 11:57am 15 May 2024 - ๐ต๐ฑPoland Graber
This needs more work with new
Drupal\Component\Plugin\Definition\PluginDefinition
.. we need to account for that as well probably as it can now be returned bygetPluginDefinition()
.Please try:
// Set the API version. $action_definition = $this->actionManager->getDefinition($this->action->getPluginId()); $output['api_version'] = \array_key_exists('api_version', $action_definition) ? $action_definition['api_version'] : '1';
Instead.
- First commit to issue fork.
- last update
7 months ago PHPLint Failed - last update
7 months ago 15 pass - Status changed to Needs review
7 months ago 1:15pm 15 May 2024 - ๐ซ๐ทFrance lazzyvn paris
@Graber
why i see in the code it uses array_key_exists instead of '??' I think ?? it's faster and safer
or compatible with old version of php, we can use !empty($array[$key]), this helps to avoid a lot of errorsFor someone who looking for dependency injection in VBO and want to get pre-configuration
use Drupal\Core\Plugin\PluginBase; class CustomVBOAction extends ViewsBulkOperationsActionBase implements ViewsBulkOperationsPreconfigurationInterface, ContainerFactoryPluginInterface { public function __construct($plugin_id, $plugin_definition, $field_definition, protected EntityTypeManagerInterface $entityTypeManager, protected AccountInterface $currentUser) { PluginBase::__construct($field_definition, $plugin_id, $plugin_definition); } // Execution get error when you need pre-configuration with getConfiguration() it will return NULL. You have to get context instead of getConfiguration() public function execute($entity = NULL) { if ($entity) { $config = $this->getConfiguration(); if (empty($config)) { $config = $this->context['configuration']; } ............ }
- ๐ต๐ฑPoland Graber
array_key_exists is strict, we know the argument must be an array, ?? works with everything which may lead to unexpected results. If array_key_exists wasn't used, we wouldn't have this issue and we wouldn't know there are changes in core that could silently break our functionalities and we'd have issues that would be much harder to discover and investigate.
Strict approach leaves no place for such issues, array must be an array, int must be int etc.