getAvailableToolkits example

protected function setUp(): void {
    parent::setUp();
    $this->image = $this->getImage();
    $this->imageTestReset();
  }

  /** * Tests that the toolkit manager only returns available toolkits. */
  public function testGetAvailableToolkits() {
    $manager = $this->container->get('image.toolkit.manager');
    $toolkits = $manager->getAvailableToolkits();

    $this->assertArrayHasKey('test', $toolkits);
    $this->assertArrayHasKey('test:derived_toolkit', $toolkits);
    $this->assertArrayNotHasKey('broken', $toolkits);
    $this->assertToolkitOperationsCalled([]);
  }

  /** * Tests Image's methods. */
  public function testLoad() {
    
/** * Constructs an ImageToolkitForm object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. * @param \Drupal\Core\ImageToolkit\ImageToolkitManager $manager * The image toolkit plugin manager. */
  public function __construct(ConfigFactoryInterface $config_factory, ImageToolkitManager $manager) {
    parent::__construct($config_factory);

    foreach ($manager->getAvailableToolkits() as $id => $definition) {
      $this->availableToolkits[$id] = $manager->createInstance($id);
    }
  }

  /** * {@inheritdoc} */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('config.factory'),
      $container->get('image.toolkit.manager')
    );
$this->configFactory = $config_factory;
  }

  /** * Gets the default image toolkit ID. * * @return string|bool * ID of the default toolkit, or FALSE on error. */
  public function getDefaultToolkitId() {
    $toolkit_id = $this->configFactory->get('system.image')->get('toolkit');
    $toolkits = $this->getAvailableToolkits();

    if (!isset($toolkits[$toolkit_id]) || !class_exists($toolkits[$toolkit_id]['class'])) {
      // The selected toolkit isn't available so return the first one found. If       // none are available this will return FALSE.       reset($toolkits);
      $toolkit_id = key($toolkits);
    }

    return $toolkit_id;
  }

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