You are here

class ReferencePreviewConverter in Bibliography & Citation 2.0.x

Same name and namespace in other branches
  1. 8 modules/bibcite_entity/src/ParamConverter/ReferencePreviewConverter.php \Drupal\bibcite_entity\ParamConverter\ReferencePreviewConverter

Provides upcasting for a reference entity in preview.

Hierarchy

Expanded class hierarchy of ReferencePreviewConverter

1 string reference to 'ReferencePreviewConverter'
bibcite_entity.services.yml in modules/bibcite_entity/bibcite_entity.services.yml
modules/bibcite_entity/bibcite_entity.services.yml
1 service uses ReferencePreviewConverter
bibcite_reference_preview in modules/bibcite_entity/bibcite_entity.services.yml
Drupal\bibcite_entity\ParamConverter\ReferencePreviewConverter

File

modules/bibcite_entity/src/ParamConverter/ReferencePreviewConverter.php, line 12

Namespace

Drupal\bibcite_entity\ParamConverter
View source
class ReferencePreviewConverter implements ParamConverterInterface {

  /**
   * Stores the tempstore factory.
   *
   * @var \Drupal\Core\TempStore\PrivateTempStoreFactory
   */
  protected $tempStoreFactory;

  /**
   * Constructs a new ReferencePreviewConverter.
   *
   * @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
   *   The factory for the temp store object.
   */
  public function __construct(PrivateTempStoreFactory $temp_store_factory) {
    $this->tempStoreFactory = $temp_store_factory;
  }

  /**
   * {@inheritdoc}
   */
  public function convert($value, $definition, $name, array $defaults) {
    $store = $this->tempStoreFactory
      ->get('bibcite_reference_preview');
    if ($form_state = $store
      ->get($value)) {
      return $form_state
        ->getFormObject()
        ->getEntity();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function applies($definition, $name, Route $route) {
    if (!empty($definition['type']) && $definition['type'] == 'bibcite_reference_preview') {
      return TRUE;
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ReferencePreviewConverter::$tempStoreFactory protected property Stores the tempstore factory.
ReferencePreviewConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
ReferencePreviewConverter::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert
ReferencePreviewConverter::__construct public function Constructs a new ReferencePreviewConverter.