-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Optimize AnnotationToAttributeRector #296
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
66898c2
feat: add PluralTranslation and test for ConfigEntityType
bbrala 335b8e9
fix: codestyle
bbrala f3b8ec8
fix:L ContentEntityType
bbrala a95b5b3
fix: overmatching )
bbrala 6aa6439
fix: tests and style
bbrala 9c6622a
fix: new Drupal\Core\StringTranslation\TranslatableMarkup should be n…
bbrala 2cc2787
feat: add documentation for core plugin conversion
bbrala 2e36bea
fix: correct paths for rector.php
bbrala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,88 @@ | ||
# Core annotation to attribute conversion | ||
|
||
To convert a plugin in core from an annotation to an attribute, you need to do the following: | ||
|
||
## Install drupal-rector | ||
```bash | ||
composer require --dev palantirnet/drupal-rector | ||
``` | ||
|
||
## Configure drupal-rector (rector.php) | ||
|
||
Create the folling file in the root of core. In this example we are converting the `ContentEntityType` and `ConfigEntityType` annotations to attributes. If you want to convert other annotations, you will need to configure the `AnnotationToAttributeRector` with the appropriate `AnnotationToAttributeConfiguration` objects. | ||
|
||
```php | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
|
||
return static function(RectorConfig $rectorConfig): void { | ||
$rectorConfig->ruleWithConfiguration(\DrupalRector\Drupal10\Rector\Deprecation\AnnotationToAttributeRector::class, [ | ||
|
||
// Setting both introduce and remove version to 10.x means the comments are not kept. Which is good for core. ;) | ||
new \DrupalRector\Drupal10\Rector\ValueObject\AnnotationToAttributeConfiguration('10.0.0', '10.0.0', 'ContentEntityType', 'Drupal\Core\Entity\Attribute\ContentEntityType'), | ||
new \DrupalRector\Drupal10\Rector\ValueObject\AnnotationToAttributeConfiguration('10.0.0', '10.0.0', 'ConfigEntityType', 'Drupal\Core\Entity\Attribute\ConfigEntityType'), | ||
]); | ||
|
||
$rectorConfig->autoloadPaths([ | ||
'./lib', | ||
'./modules', | ||
'./profiles', | ||
'./themes' | ||
]); | ||
|
||
|
||
$rectorConfig->skip([ | ||
'*/upgrade_status/tests/modules/*', | ||
'*/ProxyClass/*', | ||
'*/tests/fixtures/*', | ||
'*/vendor/*', | ||
]); | ||
$rectorConfig->fileExtensions([ | ||
'php', | ||
'module', | ||
'theme', | ||
'install', | ||
'profile', | ||
'inc', | ||
'engine' | ||
]); | ||
$rectorConfig->importNames(FALSE, FALSE); | ||
$rectorConfig->importShortClasses(FALSE); | ||
}; | ||
``` | ||
## Running rector against core | ||
|
||
Running will take a while. You can run against specific directories like so: | ||
|
||
```bash | ||
vendor/bin/rector process ./core/lib | ||
vendor/bin/rector process ./core/modules | ||
vendor/bin/rector process ./core/themes | ||
``` | ||
|
||
Or run against speific modules: | ||
|
||
```bash | ||
vendor/bin/rector process ./core/modules/system | ||
vendor/bin/rector process ./core/modules/user | ||
``` | ||
|
||
Or if you have horsepower, run against the whole of core: | ||
|
||
```bash | ||
vendor/bin/rector process ./core | ||
``` | ||
|
||
## Review the changes | ||
|
||
Always review the changes. Rector is a tool to help you, not to do the work for you. It will not be able to convert everything, and it may make mistakes. Make sure you understand the changes and that they are correct. | ||
|
||
## Reporting errors | ||
|
||
If you find an error, please report it to the rector project. You can do this by creating an issue in the rector project on Drupal.org. | ||
|
||
We are also available on the #rector channel on Drupal Slack. | ||
|
||
@bbrala @mglaman @agentrickard |
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These settings and you're in
core
but the script execution looks like it's from the directory aboveThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right