class RateWidgetBaseForm in Rate 8.2
Form controller for rate vote forms.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
- class \Drupal\Core\Entity\ContentEntityForm implements ContentEntityFormInterface
- class \Drupal\rate\Form\RateWidgetBaseForm
- class \Drupal\Core\Entity\ContentEntityForm implements ContentEntityFormInterface
- class \Drupal\Core\Entity\EntityForm implements EntityFormInterface
Expanded class hierarchy of RateWidgetBaseForm
File
- src/
Form/ RateWidgetBaseForm.php, line 23
Namespace
Drupal\rate\FormView source
class RateWidgetBaseForm extends ContentEntityForm {
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* The votingapi result manager.
*
* @var \Drupal\votingapi\VoteResultFunctionManager
*/
protected $votingapiResult;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $account;
/**
* The logger instance.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* The config factory wrapper to fetch settings.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $config;
/**
* Constructs a RateWidgetBaseForm object.
*
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\votingapi\VoteResultFunctionManager $votingapi_result
* Vote result function service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager service.
* @param \Drupal\Core\Session\AccountInterface $account
* The account service.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, VoteResultFunctionManager $votingapi_result, EntityTypeManagerInterface $entity_type_manager, AccountInterface $account, LoggerInterface $logger, ConfigFactoryInterface $config_factory) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
$this->time = $time;
$this->votingapiResult = $votingapi_result;
$this->entityTypeManager = $entity_type_manager;
$this->account = $account;
$this->logger = $logger;
$this->config = $config_factory
->get('rate.settings');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.repository'), $container
->get('entity_type.bundle.info'), $container
->get('datetime.time'), $container
->get('plugin.manager.votingapi.resultfunction'), $container
->get('entity_type.manager'), $container
->get('current_user'), $container
->get('logger.factory')
->get('rate'), $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
$entity = $this
->getEntity();
$voted_entity_type = $entity
->getVotedEntityType();
$voted_entity_id = $entity
->getVotedEntityId();
$voted_entity = $this->entityTypeManager
->getStorage($voted_entity_type)
->load($voted_entity_id);
$additional_form_id_parts = [];
$additional_form_id_parts[] = $voted_entity
->getEntityTypeId();
$additional_form_id_parts[] = $voted_entity
->bundle();
$additional_form_id_parts[] = $voted_entity
->id();
$additional_form_id_parts[] = $entity
->bundle();
$additional_form_id_parts[] = $entity->rate_widget->value;
$additional_form_id_parts[] = $entity
->get('user_id')->target_id;
$form_id = implode('_', $additional_form_id_parts);
return $form_id;
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$entity = $this
->getEntity();
$voted_entity_type = $entity
->getVotedEntityType();
$voted_entity_id = $entity
->getVotedEntityId();
$voted_entity = $this->entityTypeManager
->getStorage($voted_entity_type)
->load($voted_entity_id);
$result_function = $this
->getResultFunction($form_state);
$options = $form_state
->get('options');
$option_classes = $form_state
->get('classes');
$form_id = Html::getUniqueId('rate-widget-base-form');
$plugin = $form_state
->get('plugin');
$settings = $form_state
->get('settings');
$voting = $settings
->get('voting');
$display = $settings
->get('display');
$results = $settings
->get('results');
$template = $settings
->get('template');
$rate_widget = $form_state
->get('rate_widget');
$value_type = $entity
->get('value_type')->value;
$form['#cache']['contexts'][] = 'user.permissions';
$form['#cache']['contexts'][] = 'user.roles:authenticated';
$form['#attributes']['id'] = $form_id;
$rate_options = [];
// Remove labels on all templates, except for options and labelled widgets.
$labelled_widgets = [
'yesno',
'custom',
'emotion',
];
if ($value_type != 'option') {
if (!in_array($template, $labelled_widgets)) {
// Remove the labels.
foreach ($options as $key => $value) {
$rate_options[$key] = '';
}
}
else {
$rate_options = $options;
}
}
else {
// Options with labels.
$rate_options = $options;
}
$form['value'] = [
'#prefix' => '<div class="' . $template . '-rating-wrapper">',
'#suffix' => '</div>',
'#type' => 'radios',
'#options' => $rate_options,
'#default_value' => $entity
->isNew() ? NULL : (int) $entity
->getValue(),
'#attributes' => [
'class' => [
$template . '-rating-input',
],
],
'#theme_wrappers' => [],
'#wrapped_label' => TRUE,
];
$vote_type = $entity
->bundle();
$votes = [];
$user_id = $entity
->get('user_id')->target_id;
if (isset($results['result_type'])) {
if ($results['result_type'] == 'user_vote_empty' || $results['result_type'] == 'user_vote_average') {
$votes = $plugin
->getVotes($form_state
->get('entity_type'), $form_state
->get('entity_bundle'), $form_state
->get('entity_id'), $vote_type, $value_type, $rate_widget, $user_id);
if ($results['result_type'] == 'user_vote_average' && count($votes) == 0) {
$votes = $plugin
->getVotes($form_state
->get('entity_type'), $form_state
->get('entity_bundle'), $form_state
->get('entity_id'), $vote_type, $value_type, $rate_widget);
}
}
else {
$votes = $plugin
->getVotes($form_state
->get('entity_type'), $form_state
->get('entity_bundle'), $form_state
->get('entity_id'), $vote_type, $value_type, $rate_widget);
}
}
// Sum of all options for numberupdown.
$all_votes = 0;
$count_votes = 0;
foreach ($votes as $vote) {
$all_votes += array_sum($vote);
$count_votes += count($vote);
}
// Save the results for each option separately and add classes.
if (isset($template) && $template != 'fivestar') {
$form['value']['#attributes']['class'][] = 'rating-input';
foreach ($options as $key => $option) {
$form['value'][$key]['#attributes']['twig-suggestion'] = 'rating-input';
$form['value'][$key]['#attributes']['class'][] = 'rating-input';
$form['value'][$key]['#attributes']['class'][] = $template . '-rating-input';
// Set the option results.
if (isset($results['result_type']) && $results['result_type'] != 'vote_hidden') {
if ($template == 'numberupdown') {
if ($key > 0) {
$form['value'][$key]['#option_result'] = isset($all_votes) ? $all_votes : 0;
}
}
else {
// Use sum for points and count for option.
if ($value_type == 'option') {
$vote_sum[$key] = isset($votes[$key]) ? count($votes[$key]) : 0;
}
else {
$vote_sum[$key] = isset($votes[$key]) ? array_sum($votes[$key]) : 0;
}
$form['value'][$key]['#option_result'] = $vote_sum[$key] < 0 ? $vote_sum[$key] * -1 : $vote_sum[$key];
}
}
if (isset($option_classes[$key]) && $option_classes[$key] != NULL) {
$form['value'][$key]['#label_attributes']['class'][] = 'rating-label';
$form['value'][$key]['#label_attributes']['class'][] = 'rating-label-' . $template;
$form['value'][$key]['#label_attributes']['class'][] = 'rating-label-' . $template . '-' . strtolower(Html::cleanCssIdentifier($option));
$form['value'][$key]['#label_attributes']['class'][] = $option_classes[$key];
}
else {
$form['value'][$key]['#label_attributes']['class'][] = 'rating-label';
$form['value'][$key]['#label_attributes']['class'][] = $template . '-rating-label';
$form['value'][$key]['#label_attributes']['class'][] = $template . '-rating-label-' . strtolower(Html::cleanCssIdentifier($option));
}
}
}
else {
foreach ($options as $key => $option) {
// Add attributes and classes to the inputs.
$form['value'][$key]['#attributes']['twig-suggestion'] = 'rating-input';
$form['value'][$key]['#attributes']['class'][] = 'rating-input';
$form['value'][$key]['#attributes']['class'][] = $template . '-rating-input';
$form['value'][$key]['#attributes']['class'][] = $template . '-rating-input-' . $key;
// Add attributes and classes to the labels.
$form['value'][$key]['#label_attributes']['class'][] = 'rating-label';
$form['value'][$key]['#label_attributes']['class'][] = $template . '-rating-label';
$form['value'][$key]['#label_attributes']['class'][] = $template . '-rating-label-' . $key;
if (isset($option_classes[$key]) && $option_classes[$key] != NULL) {
$form['value'][$key]['#label_attributes']['class'][] = $option_classes[$key];
}
}
// Show the result after the last option.
$entity_value = $entity
->getValue();
if (isset($results['result_type']) && $results['result_type'] != 'vote_hidden') {
if ($results['result_type'] == 'user_vote_empty') {
$vote_avg = isset($entity_value) ? $entity_value : 0;
}
elseif ($results['result_type'] == 'user_vote_average') {
$vote_avg = isset($entity_value) ? $entity_value : number_format($this
->getResults($result_function), 1);
}
elseif ($results['result_type'] == 'vote_average') {
$vote_avg = number_format($this
->getResults($result_function), 1);
}
$form['value'][$key]['#option_result'] = $vote_avg;
// Show the average value as stars.
if ($entity
->isNew()) {
if ($results['result_type'] == 'user_vote_average' || $results['result_type'] == 'vote_average') {
foreach ($options as $option_id => $option) {
if ($option_id <= $vote_avg) {
$form['value'][$option_id]['#label_attributes']['class']['average'] = 'average';
}
}
}
}
}
}
// Set 'rate-voted' html class to radio element.
$form = $this
->setVotedClass($form, $entity, $options);
// Set the rate widget to readonly, if the entity uses a vote deadline.
$deadline_disabled = $this
->checkDeadlineDisabled($voted_entity, $voting);
$form['value']['#deadline_disabled'] = $deadline_disabled === TRUE ? TRUE : FALSE;
if (isset($display['readonly']) && $display['readonly'] === 1 || !$plugin
->canVote($entity) || $deadline_disabled === TRUE) {
$form['value']['#disabled'] = TRUE;
$form['value']['#prefix'] = '<div class="' . $template . '-rating-wrapper rate-disabled" can-edit="false">';
}
else {
$form['value']['#disabled'] = FALSE;
$form['value']['#prefix'] = '<div class="' . $template . '-rating-wrapper rate-enabled" can-edit="true">';
}
// Take care of the widget default value.
if (!$entity
->isNew()) {
if (!isset($results['result_type']) || $results['result_type'] == '0') {
$form['value']['#default_value'] = $this
->getResults($result_function);
}
else {
$form['value']['#default_value'] = (int) $entity
->getValue();
}
}
// Get the results container.
if (isset($results['result_position']) && $results['result_position'] !== 'hidden') {
$form['result'] = [
'#theme' => 'container',
'#attributes' => [
'class' => [
'vote-result',
],
],
'#children' => [],
'#weight' => 100,
];
$form['result']['#children']['result'] = $plugin
->getVoteSummary($entity);
$form['result']['#children']['result']['#disabled'] = $form['value']['#disabled'];
$form['result']['#children']['result']['#deadline_disabled'] = $deadline_disabled;
}
// The form submit button.
$form['submit'] = $form['actions']['submit'];
$form['actions']['#access'] = FALSE;
$form['submit'] += [
'#type' => 'button',
'#attributes' => [
'class' => [
$template . '-rating-submit',
],
],
'#ajax' => [
'callback' => '::ajaxSubmit',
'event' => 'click',
'wrapper' => $form_id,
'progress' => [
'type' => NULL,
],
],
];
// Base widget template. Can create additional twig templates.
$form['#theme'] = 'rate_widget';
$form['#rate_widget'] = $rate_widget;
$form['#widget_template'] = $template;
$form['#display_settings'] = $display;
$form['#results_settings'] = $results;
$form['#results'] = $plugin
->getVoteSummary($entity);
$form['#results']['#disabled'] = $form['value']['#disabled'];
$form['#results']['#deadline_disabled'] = $deadline_disabled;
return $form;
}
/**
* Get result function.
*/
protected function getResultFunction(FormStateInterface $form_state) {
$entity = $this
->getEntity();
return $form_state
->get('resultfunction') ? $form_state
->get('resultfunction') : 'rate_average:' . $entity
->getVotedEntityType() . '.' . $form_state
->get('entity_bundle') . '.' . $entity->rate_widget->value;
}
/**
* Get results.
*/
public function getResults($result_function = FALSE, $reset = FALSE) {
$entity = $this->entity;
if ($reset) {
drupal_static_reset(__FUNCTION__);
}
$resultCache =& drupal_static(__FUNCTION__);
if (!$resultCache || !isset($resultCache[$entity
->getVotedEntityType()][$entity
->getVotedEntityId()])) {
$resultCache[$entity
->getVotedEntityType()][$entity
->getVotedEntityId()] = $this->votingapiResult
->getResults($entity
->getVotedEntityType(), $entity
->getVotedEntityId());
}
$result = isset($resultCache[$entity
->getVotedEntityType()][$entity
->getVotedEntityId()]) ? $resultCache[$entity
->getVotedEntityType()][$entity
->getVotedEntityId()] : [];
$result = !empty($result) && array_key_exists($entity
->bundle(), $result) ? $result[$entity
->bundle()] : [];
if ($result_function && array_key_exists($result_function, $result) && $result[$result_function]) {
$result = $result[$result_function];
}
else {
$result = 0;
}
return $result;
}
/**
* Ajax submit handler.
*/
public function ajaxSubmit(array $form, FormStateInterface $form_state) {
$entity = $this
->getEntity();
$settings = $form_state
->get('settings');
$options = $form_state
->get('options');
$voting = $settings
->get('voting');
$display = $settings
->get('display');
$results = $settings
->get('results');
$plugin = $form_state
->get('plugin');
$result_function = $this
->getResultFunction($form_state);
$template = $settings
->get('template');
$rate_widget = $form_state
->get('rate_widget');
$voted_entity_id = $entity
->getVotedEntityId();
$voted_entity_type = $entity
->getVotedEntityType();
$user_input = $form_state
->getUserInput()['value'];
$value_type = $entity
->get('value_type')->value;
$user_id = $entity
->get('user_id')->target_id;
$disable_log = $this->config
->get('disable_log');
$voted_entity = $this->entityTypeManager
->getStorage($voted_entity_type)
->load($voted_entity_id);
$deadline_disabled = $this
->checkDeadlineDisabled($voted_entity, $voting);
$display_readonly = isset($display['readonly']) && $display['readonly'] === 1 ? TRUE : FALSE;
if (!$plugin
->canVote($entity) || $display_readonly === TRUE || $deadline_disabled === TRUE) {
$form['value']['#disabled'] = TRUE;
$form['value']['#prefix'] = '<div class="' . $template . '-rating-wrapper rate-disabled" can-edit="false">';
}
else {
$form['value']['#disabled'] = FALSE;
$form['value']['#prefix'] = '<div class="' . $template . '-rating-wrapper rate-enabled" can-edit="true">';
}
$this
->save($form, $form_state, $display_readonly, $deadline_disabled);
// If the user clicked the same option - delete last vote.
if ($form_state
->getUserInput()['value'] == $form['value']['#default_value']) {
$entity
->delete();
if ($disable_log == FALSE) {
$message = 'Vote ' . $user_input . ' on ' . $voted_entity_id . ' was cancelled. Vote ' . $entity
->id() . ' was deleted.';
$this->logger
->notice($message);
}
$entity = $plugin
->getEntityForVoting($form_state
->get('entity_type'), $form_state
->get('entity_bundle'), $form_state
->get('entity_id'), $entity
->bundle(), $value_type, $rate_widget, $settings, $user_id);
}
else {
if ($disable_log == FALSE) {
$message = 'Vote ' . $entity
->id() . ' saved. Voted ' . $user_input . ' on ' . $voted_entity_id . '.';
$this->logger
->notice($message);
}
}
if (isset($results['result_position']) && $results['result_position'] !== 'hidden') {
$form['result']['#children']['result'] = $plugin
->getVoteSummary($entity);
$form['#results'] = $plugin
->getVoteSummary($entity);
$form['#results']['#disabled'] = $form['value']['#disabled'];
$form['#results']['#deadline_disabled'] = $form['value']['#deadline_disabled'];
}
// Get the votes to populate the option results.
$vote_type = $entity
->bundle();
$votes = [];
if (isset($results['result_type'])) {
if ($results['result_type'] == 'user_vote_empty' || $results['result_type'] == 'user_vote_average') {
$votes = $plugin
->getVotes($form_state
->get('entity_type'), $form_state
->get('entity_bundle'), $form_state
->get('entity_id'), $vote_type, $value_type, $rate_widget, $user_id);
if ($results['result_type'] == 'user_vote_average' && count($votes) == 0) {
$votes = $plugin
->getVotes($form_state
->get('entity_type'), $form_state
->get('entity_bundle'), $form_state
->get('entity_id'), $vote_type, $value_type, $rate_widget);
}
}
else {
$votes = $plugin
->getVotes($form_state
->get('entity_type'), $form_state
->get('entity_bundle'), $form_state
->get('entity_id'), $vote_type, $value_type, $rate_widget);
}
}
// Sum/count of all options for numberupdown/fivestar.
$all_votes = 0;
$count_votes = 0;
foreach ($votes as $vote) {
$all_votes += array_sum($vote);
$count_votes += count($vote);
}
// Handle the different templates/vote types.
if (isset($template)) {
if (isset($results['result_type']) && $results['result_type'] != 'vote_hidden') {
foreach ($options as $key => $option) {
if ($template == 'numberupdown') {
if ($key > 0) {
$form['value'][$key]['#option_result'] = isset($all_votes) ? $all_votes : 0;
}
}
elseif ($template != 'fivestar') {
if ($value_type == 'option') {
$vote_sum[$key] = isset($votes[$key]) ? count($votes[$key]) : 0;
}
else {
$vote_sum[$key] = isset($votes[$key]) ? array_sum($votes[$key]) : 0;
}
$form['value'][$key]['#option_result'] = $vote_sum[$key] < 0 ? $vote_sum[$key] * -1 : $vote_sum[$key];
}
}
// Show the result after the last option (fivestar).
if ($template == 'fivestar') {
$entity_value = $entity
->getValue();
if ($results['result_type'] == 'user_vote_empty') {
$vote_avg = isset($entity_value) ? $entity_value : 0;
}
elseif ($results['result_type'] == 'user_vote_average') {
$vote_avg = isset($entity_value) ? $entity_value : number_format($this
->getResults($result_function), 1);
}
elseif ($results['result_type'] == 'vote_average') {
$vote_avg = number_format($this
->getResults($result_function), 1);
}
$form['value'][$key]['#option_result'] = $vote_avg;
if ($entity
->isNew()) {
foreach ($options as $option_id => $option) {
if ($option_id <= $vote_avg) {
$form['value'][$option_id]['#label_attributes']['class']['average'] = 'average';
}
}
}
else {
if ($results['result_type'] == 'user_vote_average' || $results['result_type'] == 'vote_average') {
foreach ($options as $option_id => $option) {
if (isset($form['value'][$option_id]['#label_attributes']['class']['average'])) {
unset($form['value'][$option_id]['#label_attributes']['class']['average']);
}
}
}
}
}
}
}
// Set 'rate-voted' html class to radio element.
$form = $this
->setVotedClass($form, $entity, $options);
$form_state
->setRebuild(TRUE);
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state, $display_readonly = FALSE, $deadline_disabled = FALSE) {
$entity = $this
->getEntity();
$plugin = $form_state
->get('plugin');
$is_bot_vote = $plugin
->isBotVote();
if ($plugin
->canVote($entity) && !$is_bot_vote) {
if ($display_readonly === FALSE || ($deadline_disabled = FALSE)) {
$return = parent::save($form, $form_state);
// @todo: Could be simplified if https://www.drupal.org/project/votingapi/issues/3159592 was done.
$voted_entity_id = $entity
->getVotedEntityId();
$voted_entity_type_id = $entity
->getVotedEntityType();
$voted_entity = $this->entityTypeManager
->getStorage($voted_entity_type_id)
->load($voted_entity_id);
Cache::invalidateTags([
'vote:' . $voted_entity
->bundle() . ':' . $voted_entity_id,
]);
return $return;
}
}
return FALSE;
}
/**
* Helper function to set 'rate-voted' html class to radio element.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\votingapi\Entity\Vote $vote_entity
* Vote entity.
* @param array $radio_options
* Form radio options.
*
* @return array
* The form structure.
*/
protected function setVotedClass(array $form, Vote $vote_entity, array $radio_options) {
if (!$vote_entity
->isNew()) {
$vote_value = (int) $vote_entity
->getValue();
foreach ($radio_options as $key => $option) {
if ($vote_value === $key) {
$form['value'][$key]['#label_attributes']['class']['rate-voted'] = 'rate-voted';
}
else {
unset($form['value'][$key]['#label_attributes']['class']['rate-voted']);
}
}
}
else {
foreach ($radio_options as $key => $option) {
unset($form['value'][$key]['#label_attributes']['class']['rate-voted']);
}
}
return $form;
}
/**
* Helper function to check the voting deadline.
*
* @param object $voted_entity
* The voted entity object.
* @param array $voting
* The rate widget voting settings.
*
* @return bool
* True if the rate widget should be disabled as deadline has passed.
*/
protected function checkDeadlineDisabled($voted_entity, array $voting) {
$deadline_disabled = FALSE;
if (isset($voting['use_deadline']) && $voting['use_deadline'] == 1) {
// Get the rate_vote_deadline field.
if ($voted_entity
->hasField('field_rate_vote_deadline')) {
$deadline = $voted_entity
->get('field_rate_vote_deadline')
->getString();
$current_time = $this->time
->getRequestTime();
// Disable the widget if deadline to vote was set and was passed.
if (!empty($deadline) && strtotime($deadline) <= $current_time) {
$deadline_disabled = TRUE;
}
}
}
return $deadline_disabled;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentEntityForm:: |
protected | property |
The entity being used by this form. Overrides EntityForm:: |
9 |
ContentEntityForm:: |
protected | property | The entity repository service. | |
ContentEntityForm:: |
protected | property | The entity type bundle info service. | |
ContentEntityForm:: |
protected | function | Add revision form fields if the entity enabled the UI. | |
ContentEntityForm:: |
public | function |
Builds an updated entity object based upon the submitted form values. Overrides EntityForm:: |
3 |
ContentEntityForm:: |
protected | function |
Copies top-level form values to entity properties Overrides EntityForm:: |
|
ContentEntityForm:: |
protected | function | Flags violations for the current form. | 4 |
ContentEntityForm:: |
public | function |
Gets the actual form array to be built. Overrides EntityForm:: |
13 |
ContentEntityForm:: |
protected | function | Returns the bundle entity of the entity, or NULL if there is none. | |
ContentEntityForm:: |
protected | function | Gets the names of all fields edited in the form. | 4 |
ContentEntityForm:: |
public | function |
Gets the form display. Overrides ContentEntityFormInterface:: |
|
ContentEntityForm:: |
public | function |
Gets the code identifying the active form language. Overrides ContentEntityFormInterface:: |
|
ContentEntityForm:: |
protected | function | Should new revisions created on default. | |
ContentEntityForm:: |
protected | function |
Initializes the form state and the entity before the first form build. Overrides EntityForm:: |
1 |
ContentEntityForm:: |
protected | function | Initializes form language code values. | |
ContentEntityForm:: |
public | function |
Checks whether the current form language matches the entity one. Overrides ContentEntityFormInterface:: |
|
ContentEntityForm:: |
protected | function |
Prepares the entity object before the form is built first. Overrides EntityForm:: |
1 |
ContentEntityForm:: |
public | function |
Sets the form display. Overrides ContentEntityFormInterface:: |
|
ContentEntityForm:: |
protected | function | Checks whether the revision form fields should be added to the form. | |
ContentEntityForm:: |
public | function |
This is the default entity object builder function. It is called before any
other submit handler to build the new entity object to be used by the
following submit handlers. At this point of the form workflow the entity is
validated and the form state… Overrides EntityForm:: |
3 |
ContentEntityForm:: |
public | function | Updates the changed time of the entity. | |
ContentEntityForm:: |
public | function | Updates the form language to reflect any change to the entity language. | |
ContentEntityForm:: |
public | function |
Button-level validation handlers are highly discouraged for entity forms,
as they will prevent entity validation from running. If the entity is going
to be saved during the form submission, this method should be manually
invoked from the button-level… Overrides FormBase:: |
3 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityForm:: |
protected | property | The module handler service. | |
EntityForm:: |
protected | property | The name of the current operation. | |
EntityForm:: |
private | property | The entity manager. | |
EntityForm:: |
protected | function | Returns an array of supported actions for the current entity form. | 29 |
EntityForm:: |
protected | function | Returns the action form element for the current entity form. | |
EntityForm:: |
public | function | Form element #after_build callback: Updates the entity with submitted data. | |
EntityForm:: |
public | function |
Returns a string identifying the base form. Overrides BaseFormIdInterface:: |
5 |
EntityForm:: |
public | function |
Gets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Determines which entity will be used by this form from a RouteMatch object. Overrides EntityFormInterface:: |
1 |
EntityForm:: |
public | function |
Gets the operation identifying the form. Overrides EntityFormInterface:: |
|
EntityForm:: |
protected | function | Invokes the specified prepare hook variant. | |
EntityForm:: |
public | function | Process callback: assigns weights and hides extra fields. | |
EntityForm:: |
public | function |
Sets the form entity. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the entity type manager for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the module handler for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function |
Sets the operation for this form. Overrides EntityFormInterface:: |
|
EntityForm:: |
public | function | ||
EntityForm:: |
public | function | ||
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RateWidgetBaseForm:: |
protected | property | The current user. | |
RateWidgetBaseForm:: |
protected | property | The config factory wrapper to fetch settings. | |
RateWidgetBaseForm:: |
protected | property |
The entity type manager. Overrides EntityForm:: |
|
RateWidgetBaseForm:: |
protected | property | The logger instance. | |
RateWidgetBaseForm:: |
protected | property |
The time service. Overrides ContentEntityForm:: |
|
RateWidgetBaseForm:: |
protected | property | The votingapi result manager. | |
RateWidgetBaseForm:: |
public | function | Ajax submit handler. | |
RateWidgetBaseForm:: |
public | function |
Form constructor. Overrides EntityForm:: |
|
RateWidgetBaseForm:: |
protected | function | Helper function to check the voting deadline. | |
RateWidgetBaseForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ContentEntityForm:: |
|
RateWidgetBaseForm:: |
public | function |
Returns a unique string identifying the form. Overrides EntityForm:: |
|
RateWidgetBaseForm:: |
protected | function | Get result function. | |
RateWidgetBaseForm:: |
public | function | Get results. | |
RateWidgetBaseForm:: |
public | function |
Form submission handler for the 'save' action. Overrides EntityForm:: |
|
RateWidgetBaseForm:: |
protected | function | Helper function to set 'rate-voted' html class to radio element. | |
RateWidgetBaseForm:: |
public | function |
Constructs a RateWidgetBaseForm object. Overrides ContentEntityForm:: |
|
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |