hasHandler example

#[Package('merchant-services')] class StoreClientFactoryTest extends TestCase
{
    public function testCreatesClientWithoutMiddlewares(): void
    {
        $factory = new StoreClientFactory($this->createSystemConfigService());

        $client = $factory->create();
        $config = $this->getConfigFromClient($client);
        $handler = $this->getHandlerFromConfig($config);

        static::assertTrue($handler->hasHandler());
    }

    public function testCreatesClientWithMiddlewares(): void
    {
        $factory = new StoreClientFactory($this->createSystemConfigService());

        $client = $factory->create([$this->createMock(VerifyResponseSignatureMiddleware::class)]);
        $config = $this->getConfigFromClient($client);
        $handler = $this->getHandlerFromConfig($config);

        static::assertTrue($handler->hasHandler());
    }
/** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();

    $entity_type_id = $this->definition['entity_type'];
    $bundle_entity_type = $this->entityTypeManager->getDefinition($entity_type_id)->getBundleEntityType();

    // The bundle entity type might not exist. For example, users do not have     // bundles.     if ($this->entityTypeManager->hasHandler($bundle_entity_type, 'storage')) {
      $bundle_entity_storage = $this->entityTypeManager->getStorage($bundle_entity_type);

      foreach ($bundle_entity_storage->loadMultiple(array_keys($this->options['bundles'])) as $bundle_entity) {
        $dependencies[$bundle_entity->getConfigDependencyKey()][] = $bundle_entity->getConfigDependencyName();
      }
    }

    return $dependencies;
  }

  /** * {@inheritdoc} */
$apple = $this->prophesize(EntityTypeInterface::class);
    $apple->hasHandlerClass('storage')->willReturn(TRUE);

    $banana = $this->prophesize(EntityTypeInterface::class);
    $banana->hasHandlerClass('storage')->willReturn(FALSE);

    $this->setUpEntityTypeDefinitions([
      'apple' => $apple,
      'banana' => $banana,
    ]);

    $entity_type = $this->entityTypeManager->hasHandler($entity_type_id, 'storage');
    $this->assertSame($expected$entity_type);
  }

  /** * Provides test data for testHasHandler(). * * @return array * Test data. */
  public function providerTestHasHandler() {
    return [
      [


  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    // Clear the cache.     \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();

    // Invalidate the render cache for all affected entities.     $entity_type = $this->getFieldStorageDefinition()->getTargetEntityTypeId();
    if ($this->entityTypeManager()->hasHandler($entity_type, 'view_builder')) {
      $this->entityTypeManager()->getViewBuilder($entity_type)->resetCache();
    }
  }

  /** * {@inheritdoc} */
  public function getLabel() {
    return $this->label();
  }

  
'#empty' => $this->t('This workspace has no changes.'),
      ];

      $changes_count = [];
      foreach ($all_tracked_entities as $entity_type_id => $tracked_entities) {
        // Ensure that newest revisions are displayed at the top.         krsort($tracked_entities);

        $changes_count[$entity_type_id] = $this->entityTypeManager->getDefinition($entity_type_id)->getCountLabel(count($tracked_entities));

        $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);
        if ($this->entityTypeManager->hasHandler($entity_type_id, 'list_builder')) {
          $list_builder = $this->entityTypeManager->getListBuilder($entity_type_id);
        }
        else {
          $list_builder = $this->entityTypeManager->createHandlerInstance(EntityListBuilder::class$entity_type);
        }

        $revisions = $this->entityTypeManager->getStorage($entity_type_id)->loadMultipleRevisions(array_keys($tracked_entities));

        // Load all users at once.         $user_ids = [];
        foreach ($revisions as $revision) {
          
public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    $entity_type_manager = $this->entityTypeManager();
    $bundle_of = $this->getEntityType()->getBundleOf();
    if (!$update) {
      \Drupal::service('entity_bundle.listener')->onBundleCreate($this->id()$bundle_of);
    }
    else {
      // Invalidate the render cache of entities for which this entity       // is a bundle.       if ($entity_type_manager->hasHandler($bundle_of, 'view_builder')) {
        $entity_type_manager->getViewBuilder($bundle_of)->resetCache();
      }
      // Entity bundle field definitions may depend on bundle settings.       \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
      $this->entityTypeBundleInfo()->clearCachedBundles();
    }
  }

  /** * {@inheritdoc} */
  

    $this->getDerivativeDefinitions($base_plugin_definition);
    return $this->derivatives[$derivative_id];
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      // Just add support for entity types which have a views integration.       if (($base_table = $entity_type->getBaseTable()) && $this->viewsData->get($base_table) && $this->entityTypeManager->hasHandler($entity_type_id, 'view_builder')) {
        $this->derivatives[$entity_type_id] = [
          'id' => 'entity:' . $entity_type_id,
          'provider' => 'views',
          'title' => $entity_type->getLabel(),
          'help' => $this->t('Display the @label', ['@label' => $entity_type->getLabel()]),
          'base' => [$entity_type->getDataTable() ?: $entity_type->getBaseTable()],
          'entity_type' => $entity_type_id,
          'display_types' => ['normal'],
          'class' => $base_plugin_definition['class'],
        ];
      }
    }
$this->pluginManager = \Drupal::service('plugin.manager.field.formatter');

    parent::__construct($values$entity_type);
  }

  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    // Reset the render cache for the target entity type.     parent::postSave($storage$update);
    if (\Drupal::entityTypeManager()->hasHandler($this->targetEntityType, 'view_builder')) {
      \Drupal::entityTypeManager()->getViewBuilder($this->targetEntityType)->resetCache();
    }
  }

  /** * {@inheritdoc} */
  public function getRenderer($field_name) {
    if (isset($this->plugins[$field_name])) {
      return $this->plugins[$field_name];
    }

    
public function __construct(AccountInterface $user, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, AdminContext $admin_context) {
    $this->user = $user;
    $this->configFactory = $config_factory;
    $this->entityTypeManager = $entity_type_manager;
    $this->adminContext = $admin_context;
  }

  /** * {@inheritdoc} */
  public function applies(RouteMatchInterface $route_match) {
    return ($this->entityTypeManager->hasHandler('user_role', 'storage') && $this->user->hasPermission('view the administration theme') && $this->adminContext->isAdminRoute($route_match->getRouteObject()));
  }

  /** * {@inheritdoc} */
  public function determineActiveTheme(RouteMatchInterface $route_match) {
    return $this->configFactory->get('system.theme')->get('admin') ?: NULL;
  }

}
static::assertEquals(self::TEST_STORE_URI, $config['base_uri']);

        static::assertArrayHasKey('Content-Type', $config['headers']);
        static::assertEquals('application/json', $config['headers']['Content-Type']);

        static::assertArrayHasKey('Accept', $config['headers']);
        static::assertEquals('application/vnd.api+json,application/json', $config['headers']['Accept']);

        /** @var HandlerStack $stack */
        $stack = $config['handler'];

        static::assertTrue($stack->hasHandler());
    }

    private function getSystemConfigService(): SystemConfigService
    {
        return $this->getContainer()->get(SystemConfigService::class);
    }

    /** * @return array<string, mixed> */
    private function getConfigFromClient(ClientInterface $client): array
    {
$this->negotiator = $negotiator;
    $this->blockManager = $block_manager;
    $this->themeHandler = $theme_handler;
    $this->blockStorage = $block_storage;
  }

  /** * {@inheritdoc} */
  public static function create(ContainerInterface $container) {
    $entity_type_manager = $container->get('entity_type.manager');
    $block_storage = $entity_type_manager->hasHandler('block', 'storage') ? $entity_type_manager->getStorage('block') : NULL;
    return new static(
      $container->get('config.factory'),
      $container->get('language_manager'),
      $container->get('language_negotiator'),
      $container->get('plugin.manager.block'),
      $container->get('theme_handler'),
      $block_storage
    );
  }

  /** * {@inheritdoc} */
    \Drupal::service('field_storage_definition.listener')->onFieldStorageDefinitionUpdate($this$this->original);
  }

  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    if ($update) {
      // Invalidate the render cache for all affected entities.       $entity_type_manager = \Drupal::entityTypeManager();
      $entity_type = $this->getTargetEntityTypeId();
      if ($entity_type_manager->hasHandler($entity_type, 'view_builder')) {
        $entity_type_manager->getViewBuilder($entity_type)->resetCache();
      }
    }
  }

  /** * {@inheritdoc} */
  public static function preDelete(EntityStorageInterface $storage, array $field_storages) {
    /** @var \Drupal\Core\Field\DeletedFieldsRepositoryInterface $deleted_fields_repository */
    $deleted_fields_repository = \Drupal::service('entity_field.deleted_fields_repository');

    
Home | Imprint | This part of the site doesn't use cookies.