-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add phpstorm completion for OOP hooks
- Loading branch information
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DrupalCodeGenerator\Command\PhpStormMeta; | ||
|
||
use DrupalCodeGenerator\Asset\File; | ||
use DrupalCodeGenerator\Helper\Drupal\HookInfo; | ||
use DrupalCodeGenerator\Helper\Drupal\ModuleInfo; | ||
|
||
/** | ||
* Generates PhpStorm meta-data for Drupal hooks. | ||
*/ | ||
final class Hooks { | ||
|
||
/** | ||
* Constructs the object. | ||
*/ | ||
public function __construct( | ||
private readonly HookInfo $hookInfo, | ||
private readonly ModuleInfo $moduleInfo, | ||
) {} | ||
|
||
/** | ||
* Generator callback. | ||
*/ | ||
public function __invoke(): File { | ||
$hooks = \array_keys($this->hookInfo->getHookTemplates()); | ||
$modules = \array_keys($this->moduleInfo->getExtensions()); | ||
return File::create('.phpstorm.meta.php/hooks.php') | ||
->template('hooks.php.twig') | ||
->vars(['hooks' => $hooks, 'modules' => $modules]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPSTORM_META { | ||
|
||
registerArgumentsSet('hooks', | ||
{% for hook in hooks %} | ||
'{{ hook }}', | ||
{% endfor %} | ||
); | ||
registerArgumentsSet('modules', | ||
{% for module in modules %} | ||
'{{ module }}', | ||
{% endfor %} | ||
); | ||
expectedArguments(\Drupal\Core\Hook\Attribute\Hook::__construct(), 0, argumentsSet('hooks')); | ||
expectedArguments(\Drupal\Core\Hook\Attribute\Hook::__construct(), 2, argumentsSet('modules')); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters