Find the best Rector rule to solve your problem. Searching through 1004 rules.
Found 14 rules, grouped by set: Clear
Replace use of deprecated Drupal\Component\Utility\ToStringTrait with a direct __toString() method.
use Drupal\Component\Utility\ToStringTrait;
class MyClass {
- use ToStringTrait;
+ public function __toString(): string {
+ return (string) $this->render();
+ }
public function render() {
return 'hello';
}
}
Removes deprecated $form['#submit'][] = 'automated_cron_settings_submit' handler assignments (drupal:11.4.0)
-$form['#submit'][] = 'automated_cron_settings_submit';
$form['#submit'][] = 'mymodule_settings_submit';
Replace integer #access values with proper booleans in render arrays.
-$build = ['#markup' => 'foo', '#access' => 1];
+$build = ['#markup' => 'foo', '#access' => true];
Replace deprecated DrupalTestCaseTrait::getDrupalRoot() calls with $this->root property access in Drupal test classes.
-$dir = $this->getDrupalRoot() . '/core/tests/fixtures';
+$dir = $this->root . '/core/tests/fixtures';
Replace deprecated system_sort_themes() string callback with an inline static closure
-uasort($theme_groups['installed'], 'system_sort_themes');
+uasort($theme_groups['installed'], static function ($a, $b) {
+ if ($a->is_default) {
+ return -1;
+ }
+ if ($b->is_default) {
+ return 1;
+ }
+ return strcasecmp($a->info['name'], $b->info['name']);
+});
Replace deprecated global hide() and show() functions with direct #printed property assignment on the render element.
-hide($element);
+$element['#printed'] = TRUE;
Remove deprecated cacheExpire() overrides from Views CachePluginBase subclasses
-class MyCache extends CachePluginBase { protected function cacheExpire($type) { return 0; } }
+class MyCache extends CachePluginBase { }
Remove deprecated $toolkit argument from ImageToolkitOperationBase::__construct(). The toolkit is now injected via setToolkit() by the plugin manager.
-use Drupal\Core\ImageToolkit\ImageToolkitInterface;
use Drupal\Core\ImageToolkit\ImageToolkitOperationBase;
use Psr\Log\LoggerInterface;
class MyOperation extends ImageToolkitOperationBase {
- public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitInterface $toolkit, LoggerInterface $logger) {
- parent::__construct($configuration, $plugin_id, $plugin_definition, $toolkit, $logger);
+ public function __construct(array $configuration, $plugin_id, array $plugin_definition, LoggerInterface $logger) {
+ parent::__construct($configuration, $plugin_id, $plugin_definition, $logger);
}
}
Removes deprecated LinkWidget::validateTitleElement() calls. Validation is now handled by LinkTitleRequiredConstraint on the LinkItem field type (drupal:11.4.0)
-LinkWidget::validateTitleElement($element, $form_state, $form);
$element['#value'] = $value;
Replaces deprecated user_load_by_name() and user_load_by_mail() with entity storage loadByProperties()
-$account = user_load_by_name($name);
+$account = array_values(\Drupal::entityTypeManager()->getStorage('user')->loadByProperties(['name' => $name]))[0] ?? FALSE;
Remove deprecated KernelTestBase::installSchema('system', 'sequences') calls; the sequences table was removed in Drupal 12.
-$this->installEntitySchema('node');
-$this->installSchema('system', ['sequences']);
+$this->installEntitySchema('node');
Replace deprecated check_markup() calls with a processed_text render array.
-check_markup($text, $format_id);
+['#type' => 'processed_text', '#text' => $text, '#format' => $format_id];
Remove deprecated CachePluginBase::getRowCacheKeys() and getRowId() calls and array item values
-['keys' => $cache_plugin->getRowCacheKeys($row), 'tags' => []]
+['tags' => []]
Remove deprecated EntityTypeInterface::setUriCallback() calls
-$entity_type->setLinkTemplate('canonical', '/mymodule/{entity}');
-$entity_type->setUriCallback('my_entity_uri');
+$entity_type->setLinkTemplate('canonical', '/mymodule/{entity}');