Revert "fetch -> web/fetch for everything"

This reverts commit ca790b1716.
This commit is contained in:
Jon Corbin
2026-01-12 14:03:48 -05:00
parent e8577617b0
commit 5afc90e633
69 changed files with 360 additions and 360 deletions

View File

@@ -1,7 +1,7 @@
---
description: 'Expert assistant for Drupal development, architecture, and best practices using PHP 8.3+ and modern Drupal patterns'
model: GPT-4.1
tools: ['codebase', 'terminalCommand', 'edit/editFiles', 'web/fetch', 'githubRepo', 'runTests', 'problems']
tools: ['codebase', 'terminalCommand', 'edit/editFiles', 'fetch', 'githubRepo', 'runTests', 'problems']
---
# Drupal Expert
@@ -157,11 +157,11 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DecoratedEntityTypeManager implements EntityTypeManagerInterface {
public function __construct(
protected EntityTypeManagerInterface $entityTypeManager
) {}
// Implement all interface methods, delegating to wrapped service
// Add custom logic where needed
}
@@ -190,17 +190,17 @@ use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class MyModuleSubscriber implements EventSubscriberInterface {
public function __construct(
protected RouteMatchInterface $routeMatch
) {}
public static function getSubscribedEvents(): array {
return [
KernelEvents::REQUEST => ['onRequest', 100],
];
}
public function onRequest(RequestEvent $event): void {
// Custom logic on every request
}
@@ -222,7 +222,7 @@ use Drupal\Component\Annotation\Plugin;
* @Annotation
*/
class CustomProcessor extends Plugin {
public string $id;
public string $label;
public string $description = '';
@@ -263,7 +263,7 @@ use Drupal\Core\Queue\QueueWorkerBase;
* )
*/
class MyModuleProcessor extends QueueWorkerBase {
public function processItem($data): void {
// Process queue item
}
@@ -322,10 +322,10 @@ use Drupal\Core\Field\BaseFieldDefinition;
* )
*/
class Product extends ContentEntityBase {
public static function baseFieldDefinitions(EntityTypeInterface $entity_type): array {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setRequired(TRUE)
@@ -335,7 +335,7 @@ class Product extends ContentEntityBase {
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['price'] = BaseFieldDefinition::create('decimal')
->setLabel(t('Price'))
->setSetting('precision', 10)
@@ -346,15 +346,15 @@ class Product extends ContentEntityBase {
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
return $fields;
}
}
@@ -383,7 +383,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* )
*/
class RecentProductsBlock extends BlockBase implements ContainerFactoryPluginInterface {
public function __construct(
array $configuration,
$plugin_id,
@@ -392,7 +392,7 @@ class RecentProductsBlock extends BlockBase implements ContainerFactoryPluginInt
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self {
return new self(
$configuration,
@@ -401,13 +401,13 @@ class RecentProductsBlock extends BlockBase implements ContainerFactoryPluginInt
$container->get('entity_type.manager')
);
}
public function defaultConfiguration(): array {
return [
'count' => 5,
] + parent::defaultConfiguration();
}
public function blockForm($form, FormStateInterface $form_state): array {
$form['count'] = [
'#type' => 'number',
@@ -418,23 +418,23 @@ class RecentProductsBlock extends BlockBase implements ContainerFactoryPluginInt
];
return $form;
}
public function blockSubmit($form, FormStateInterface $form_state): void {
$this->configuration['count'] = $form_state->getValue('count');
}
public function build(): array {
$count = $this->configuration['count'];
$storage = $this->entityTypeManager->getStorage('product');
$query = $storage->getQuery()
->accessCheck(TRUE)
->sort('created', 'DESC')
->range(0, $count);
$ids = $query->execute();
$products = $storage->loadMultiple($ids);
return [
'#theme' => 'item_list',
'#items' => array_map(
@@ -467,9 +467,9 @@ use Psr\Log\LoggerInterface;
* Service for managing products.
*/
class ProductManager {
protected LoggerInterface $logger;
public function __construct(
protected EntityTypeManagerInterface $entityTypeManager,
protected ConfigFactoryInterface $configFactory,
@@ -477,7 +477,7 @@ class ProductManager {
) {
$this->logger = $loggerFactory->get('mymodule');
}
/**
* Creates a new product.
*
@@ -492,13 +492,13 @@ class ProductManager {
$product = $this->entityTypeManager
->getStorage('product')
->create($values);
$product->save();
$this->logger->info('Product created: @name', [
'@name' => $product->label(),
]);
return $product;
}
catch (\Exception $e) {
@@ -537,23 +537,23 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* Returns responses for My Module routes.
*/
class ProductController extends ControllerBase {
public function __construct(
protected ProductManager $productManager
) {}
public static function create(ContainerInterface $container): self {
return new self(
$container->get('mymodule.product_manager')
);
}
/**
* Displays a list of products.
*/
public function list(): array {
$products = $this->productManager->getRecentProducts(10);
return [
'#theme' => 'mymodule_product_list',
'#products' => $products,
@@ -594,15 +594,15 @@ use Drupal\mymodule\Entity\Product;
* @group mymodule
*/
class ProductTest extends KernelTestBase {
protected static $modules = ['mymodule', 'user', 'system'];
protected function setUp(): void {
parent::setUp();
$this->installEntitySchema('product');
$this->installEntitySchema('user');
}
/**
* Tests product creation.
*/
@@ -612,7 +612,7 @@ class ProductTest extends KernelTestBase {
'price' => 99.99,
]);
$product->save();
$this->assertNotEmpty($product->id());
$this->assertEquals('Test Product', $product->label());
$this->assertEquals(99.99, $product->get('price')->value);