You are here

class FocalPoint in Thunder 6.2.x

Resolves the focal point positions for a file.

Plugin annotation


@DataProducer(
  id = "focal_point",
  name = @Translation("FocalPoint"),
  description = @Translation("Resolves the focal point positions for a file."),
  produces = @ContextDefinition("any",
    label = @Translation("Focal point positions")
  ),
  consumes = {
    "file" = @ContextDefinition("entity",
      label = @Translation("Root value")
    )
  }
)

Hierarchy

Expanded class hierarchy of FocalPoint

1 string reference to 'FocalPoint'
ThunderSchema::resolveBaseTypes in modules/thunder_gqls/src/Plugin/GraphQL/Schema/ThunderSchema.php
Resolve custom types, that are used in multiple places.

File

modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/FocalPoint.php, line 30

Namespace

Drupal\thunder_gqls\Plugin\GraphQL\DataProducer
View source
class FocalPoint extends DataProducerPluginBase implements ContainerFactoryPluginInterface {

  /**
   * The focal point config.
   *
   * @var \Drupal\Core\Config\ImmutableConfig
   */
  protected $config;

  /**
   * The focal point manager service.
   *
   * @var \Drupal\focal_point\FocalPointManagerInterface
   */
  protected $focalPointManager;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * {@inheritdoc}
   *
   * @codeCoverageIgnore
   */
  public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition) {
    return new static($configuration, $pluginId, $pluginDefinition, $container
      ->get('config.factory'), $container
      ->get('focal_point.manager'), $container
      ->get('module_handler'));
  }

  /**
   * FocalPoint constructor.
   *
   * @param array $configuration
   *   The plugin configuration array.
   * @param string $pluginId
   *   The plugin id.
   * @param mixed $pluginDefinition
   *   The plugin definition.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   The config factory service.
   * @param \Drupal\focal_point\FocalPointManagerInterface $focalPointManager
   *   The focal point manager service.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
   *   The module handler.
   */
  public function __construct(array $configuration, string $pluginId, $pluginDefinition, ConfigFactoryInterface $configFactory, FocalPointManagerInterface $focalPointManager, ModuleHandlerInterface $moduleHandler) {
    parent::__construct($configuration, $pluginId, $pluginDefinition);
    $this->config = $configFactory
      ->get('focal_point.settings');
    $this->focalPointManager = $focalPointManager;
    $this->moduleHandler = $moduleHandler;
  }

  /**
   * Resolve the focal point positions.
   *
   * @param \Drupal\file\FileInterface $file
   *   The entity.
   *
   * @return mixed
   *   The focal point position tag.
   */
  public function resolve(FileInterface $file) {
    if (!$this->moduleHandler
      ->moduleExists('focal_point')) {
      return '';
    }
    return $this->focalPointManager
      ->getCropEntity($file, $this->config
      ->get('crop_type'))
      ->position();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FocalPoint::$config protected property The focal point config.
FocalPoint::$focalPointManager protected property The focal point manager service.
FocalPoint::$moduleHandler protected property The module handler.
FocalPoint::create public static function @codeCoverageIgnore Overrides ContainerFactoryPluginInterface::create
FocalPoint::resolve public function Resolve the focal point positions.
FocalPoint::__construct public function FocalPoint constructor.