FieldEntry.php in Flag 8.4
File
src/Plugin/ActionLink/FieldEntry.php
View source
<?php
namespace Drupal\flag\Plugin\ActionLink;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
use Drupal\flag\FlagInterface;
use Drupal\Core\Entity\EntityInterface;
class FieldEntry extends FormEntryTypeBase {
public function getUrl($action, FlagInterface $flag, EntityInterface $entity) {
switch ($action) {
case 'flag':
return Url::fromRoute('flag.field_entry', [
'flag' => $flag
->id(),
'entity_id' => $entity
->id(),
]);
default:
return Url::fromRoute('flag.field_entry.edit', [
'flag' => $flag
->id(),
'entity_id' => $entity
->id(),
]);
}
}
public function defaultConfiguration() {
$options = parent::defaultConfiguration();
$options['flag_confirmation'] = $this
->t('Enter flagging details');
$options['edit_flagging'] = $this
->t('Edit flagging details');
$options['flag_update_button'] = $this
->t('Update flagging');
return $options;
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['display']['settings']['link_options_' . $this
->getPluginId()]['edit_flagging'] = [
'#type' => 'textfield',
'#title' => $this
->t('Edit flagging details message'),
'#default_value' => $this->configuration['edit_flagging'],
'#description' => $this
->t('Message displayed if the user has clicked the "Edit flag" link. Usually presented in the form such as, "Please enter the flagging details."'),
'#required' => TRUE,
];
$form['display']['settings']['link_options_field_entry']['flag_update_button'] = [
'#type' => 'textfield',
'#title' => $this
->t('Update flagging button text'),
'#default_value' => $this->configuration['flag_update_button'],
'#description' => $this
->t('The text for the submit button when updating a flagging.'),
'#required' => TRUE,
];
return $form;
}
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::validateConfigurationForm($form, $form_state);
$form_values = $form_state
->getValues();
if (empty($form_values['edit_flagging'])) {
$form_state
->setErrorByName('flagging_edit_title', $this
->t('An edit flagging details message is required when using the field entry link type.'));
}
}
}