Verified Commit 0daf93c5 authored by godotislate's avatar godotislate
Browse files

task: #3606411 Return the correct typehint when Drupal::classResolver() is...

task: #3606411 Return the correct typehint when Drupal::classResolver() is called with a class string

By: mstrelan
By: kieran.cott
By: longwave
By: godotislate
parent bb1b9c25
Loading
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -359,10 +359,12 @@ public static function cache($bin = 'default') {
   * One common use case is to provide a class which contains the actual code
   * of a hook implementation, without having to create a service.
   *
   * @param string $class
   * @param class-string<T>|null $class
   *   (optional) A class name to instantiate.
   *
   * @return \Drupal\Core\DependencyInjection\ClassResolverInterface|object
   * @template T of object
   *
   * @return ($class is class-string<T> ? T : \Drupal\Core\DependencyInjection\ClassResolverInterface)
   *   The class resolver or if $class is provided, a class instance with a
   *   given class definition.
   *
+4 −2
Original line number Diff line number Diff line
@@ -12,10 +12,12 @@ interface ClassResolverInterface {
   *
   * In contrast to controllers you don't specify a method.
   *
   * @param string $definition
   * @param class-string<T>|string $definition
   *   A class name or service name.
   *
   * @return object
   * @template T of object
   *
   * @return ($definition is class-string<T> ? T : object)
   *   The instance of the class.
   *
   * @throws \InvalidArgumentException
+4 −12
Original line number Diff line number Diff line
@@ -201,9 +201,7 @@ public function entityBuildDefaultsAlter(array &$build, EntityInterface $entity,
  #[Hook('entity_presave')]
  public function entityPresave(EntityInterface $entity): void {
    if (\Drupal::moduleHandler()->moduleExists('block_content')) {
      /** @var \Drupal\layout_builder\InlineBlockEntityOperations $entity_operations */
      $entity_operations = \Drupal::classResolver(InlineBlockEntityOperations::class);
      $entity_operations->handlePreSave($entity);
      \Drupal::classResolver(InlineBlockEntityOperations::class)->handlePreSave($entity);
    }
  }

@@ -213,9 +211,7 @@ public function entityPresave(EntityInterface $entity): void {
  #[Hook('entity_delete')]
  public function entityDelete(EntityInterface $entity): void {
    if (\Drupal::moduleHandler()->moduleExists('block_content')) {
      /** @var \Drupal\layout_builder\InlineBlockEntityOperations $entity_operations */
      $entity_operations = \Drupal::classResolver(InlineBlockEntityOperations::class);
      $entity_operations->handleEntityDelete($entity);
      \Drupal::classResolver(InlineBlockEntityOperations::class)->handleEntityDelete($entity);
    }
  }

@@ -233,9 +229,7 @@ public function entityUpdate(EntityInterface $entity): void {
      // If an entity's field values change, and it also has a layout override
      // in the tempstore, the tempstore must be updated to reflect those new
      // values.
      /** @var \Drupal\layout_builder\LayoutOverrideFieldHelper $override_field_helper */
      $override_field_helper = \Drupal::classResolver(LayoutOverrideFieldHelper::class);
      $override_field_helper->updateTempstoreEntityContext($entity);
      \Drupal::classResolver(LayoutOverrideFieldHelper::class)->updateTempstoreEntityContext($entity);
    }
  }

@@ -245,9 +239,7 @@ public function entityUpdate(EntityInterface $entity): void {
  #[Hook('cron')]
  public function cron(): void {
    if (\Drupal::moduleHandler()->moduleExists('block_content')) {
      /** @var \Drupal\layout_builder\InlineBlockEntityOperations $entity_operations */
      $entity_operations = \Drupal::classResolver(InlineBlockEntityOperations::class);
      $entity_operations->removeUnused();
      \Drupal::classResolver(InlineBlockEntityOperations::class)->removeUnused();
    }
  }