vimeo_player-1.0.0-rc1/src/Plugin/ECA/Condition/VimeoPlayerEvent.php
src/Plugin/ECA/Condition/VimeoPlayerEvent.php
<?php
namespace Drupal\vimeo_player\Plugin\ECA\Condition;
use Drupal\Core\Form\FormStateInterface;
use Drupal\eca\Plugin\ECA\PluginFormTrait;
use Drupal\eca\Plugin\ECA\Condition\ConditionBase;
/**
* Plugin implementation of the ECA condition of the vimeo player event.
*
* @EcaCondition(
* id = "vimeo_player_event",
* label = @Translation("Vimeo Player Event"),
* description = @Translation("Check which player event occurred."),
* eca_version_introduced = "1.0.0"
* )
*/
class VimeoPlayerEvent extends ConditionBase {
use PluginFormTrait;
/**
* {@inheritdoc}
*/
public function evaluate(): bool {
$current_event = $this->tokenService->replace($this->configuration['current_event']);
$event = $this->tokenService->replace($this->configuration['event']);
return $this->negationCheck($current_event === $event);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration(): array {
return [
'current_event' => '[vimeo_event_name]',
'event' => '',
] + parent::defaultConfiguration();
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
$form['current_event'] = [
'#type' => 'textfield',
'#title' => $this->t('Vimeo Player Eevent Occured'),
'#description' => $this->t('The vimeo player event you want to match.'),
'#default_value' => $this->configuration['current_event'],
'#weight' => -20,
];
$event_options = [
'play' => $this->t('Play'),
'playing' => $this->t('Playing'),
'ratechange' => $this->t('Rate Change'),
'volumechange' => $this->t('Volume Change'),
'ended' => $this->t('Ended'),
];
$form['event'] = [
'#type' => 'select',
'#title' => $this->t('Vimeo Player Event'),
'#description' => $this->t('The event to check.'),
'#default_value' => $this->configuration['event'],
'#required' => TRUE,
'#options' => $event_options,
];
return parent::buildConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
$this->configuration['current_event'] = $form_state->getValue('current_event');
$this->configuration['event'] = $form_state->getValue('event');
parent::submitConfigurationForm($form, $form_state);
}
}
