class ExifSettingsForm in Exif 8
Same name and namespace in other branches
- 8.2 src/Controller/ExifSettingsForm.php \Drupal\exif\Controller\ExifSettingsForm
Manage Settings forms.
@package Drupal\exif\Controller
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\exif\Controller\ExifSettingsForm implements ContainerInjectionInterface
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of ExifSettingsForm
1 string reference to 'ExifSettingsForm'
File
- src/
Controller/ ExifSettingsForm.php, line 20
Namespace
Drupal\exif\ControllerView source
class ExifSettingsForm extends ConfigFormBase implements ContainerInjectionInterface {
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs the ExifSettingsForm object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'exif_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('exif.settings');
$form['information1'] = [
'#type' => 'item',
'#title' => 'Informations',
'#markup' => t('If you have not create a media/content type for your photographies') . ', ' . t('take a look at <a href="/admin/config/media/exif/helper">the quick start page</a>.'),
];
$form['information2'] = [
'#type' => 'item',
'#title' => '',
'#markup' => t('To have a sample of metadata content, take a look at <a href="/admin/config/media/exif/sample">the sample page</a>.'),
];
$form['exif'] = [
'#type' => 'vertical_tabs',
'#prefix' => '<div class="exif">',
'#suffix' => '</div>',
'#title' => t('Image Metadata Settings'),
'#description' => t('If you have not create a media/content type for your photographies') . ', ' . t('take a look at <a href="/admin/config/media/exif/helper">the quick start page</a>.'),
];
$form['global'] = [
'#type' => 'details',
'#title' => t('Global Settings'),
'#group' => 'exif',
];
$form['global']['granularity'] = [
'#type' => 'select',
'#title' => t('Granularity'),
'#options' => [
0 => t('Default'),
1 => 'Day',
],
'#default_value' => $config
->get('granularity', 0),
'#description' => t('If a timestamp is selected (for example the date the picture was taken), you can specify here how granular the timestamp should be. If you select default it will just take whatever is available in the picture. If you select Day, the Date saved will look something like 13-12-2008. This can be useful if you want to use some kind of grouping on the data.'),
];
$form['fieldname'] = [
'#type' => 'markup',
'#value' => "My Value Goes Here",
];
$form['node'] = [
'#type' => 'details',
'#title' => t('Content types'),
'#group' => 'exif',
];
$all_nodetypes = $this->entityTypeManager
->getStorage('node_type')
->loadMultiple();
$all_nt = [];
foreach ($all_nodetypes as $item) {
$all_nt[$item
->id()] = $item
->label();
}
$form['node']['nodetypes'] = [
'#type' => 'checkboxes',
'#title' => t('Nodetypes'),
'#options' => $all_nt,
'#default_value' => $config
->get('nodetypes', []),
'#description' => t('Select nodetypes which should be checked for iptc & exif data.'),
];
// The old way (still in use so keep it).
if (Drupal::moduleHandler()
->moduleExists("file_entity")) {
$form['file'] = [
'#type' => 'details',
'#title' => t('File types'),
'#group' => 'exif',
];
$all_mt = [];
$all_filetypes = FileType::loadEnabled();
// Setup file types.
foreach ($all_filetypes as $item) {
$all_mt[$item
->id()] = $item
->label();
}
$form['file']['filetypes'] = [
'#type' => 'checkboxes',
'#title' => t('Filetypes'),
'#options' => $all_mt,
'#default_value' => $config
->get('filetypes', []),
'#description' => t('Select filetypes which should be checked for itpc & exif data.'),
];
}
else {
$form['file']['filetypes'] = [
'#type' => 'hidden',
'#value' => [],
];
}
if (Drupal::moduleHandler()
->moduleExists("media_entity")) {
$form['media'] = [
'#type' => 'details',
'#title' => t('Media types'),
'#group' => 'exif',
];
$all_mediatypes = $this->entityTypeManager
->getStorage('media_bundle')
->loadMultiple();
$all_mt = [];
foreach ($all_mediatypes as $item) {
$all_mt[$item
->id()] = $item
->label();
}
$form['media']['mediatypes'] = [
'#type' => 'checkboxes',
'#title' => t('Mediatypes'),
'#options' => $all_mt,
'#default_value' => $config
->get('mediatypes', []),
'#description' => t('Select mediatypes which should be checked for iptc & exif data.'),
];
}
else {
$form['media']['mediatypes'] = [
'#type' => 'hidden',
'#default_value' => $config
->get('mediatypes', []),
];
}
$form['global']['update_metadata'] = [
'#type' => 'checkbox',
'#title' => t('Refresh on node update'),
'#default_value' => $config
->get('update_metadata', TRUE),
'#description' => t('If media/exif enable this option, Exif data is being updated when the node is being updated.'),
];
$form['global']['extraction_solution'] = [
'#type' => 'select',
'#title' => t('which extraction solution to use on node update'),
'#options' => ExifFactory::getExtractionSolutions(),
'#default_value' => $config
->get('extraction_solution', "php_extensions"),
'#description' => t('If media/exif enable this option, Exif data is being updated when the node is being updated.'),
];
$form['global']['exiftool_location'] = [
'#type' => 'textfield',
'#title' => t('location of exiftool binary'),
'#default_value' => $config
->get('exiftool_location', "exiftool"),
'#description' => t('where is the exiftool binaries (only needed if extraction solution chosen is exiftool)'),
];
$form['global']['write_empty_values'] = [
'#type' => 'checkbox',
'#title' => t('Write empty image data?'),
'#default_value' => $config
->get('write_empty_values', TRUE),
'#description' => t("If checked all values will be written. So for example if you want to read the creation date from EXIF, but it's not available, it will just write an empty string. If unchecked, empty strings will not be written. This might be the desired behavior, if you have a default value for the CCK field."),
];
$all_vocabularies = Vocabulary::loadMultiple();
$all_vocs = [];
$all_vocs[0] = 'None';
foreach ($all_vocabularies as $item) {
$all_vocs[$item
->id()] = $item
->label();
}
$form['global']['vocabulary'] = [
'#type' => 'select',
'#title' => t('Default Vocabulary'),
'#options' => $all_vocs,
'#default_value' => $config
->get('vocabulary', []),
'#description' => t('Select vocabulary which should be used for iptc & exif data.') . t('If you think no vocabulary is usable for the purpose') . ', ' . t('take a look at <a href="/admin/config/media/exif/helper">the quick start page</a>.'),
];
// TODO : Check if the media module is install to add automatically
// TODO : the image type active and add active default exif field.
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->getValue('extraction_solution') == 'simple_exiftool' && !is_executable($form_state
->getValue('exiftool_location'))) {
$form_state
->setErrorByName('exiftool_location', $this
->t('The location provided for exiftool is not correct. Please ensure the exiftool location exists and is executable.'));
}
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
foreach ([
'nodetypes',
'filetypes',
'mediatypes',
] as $entity_type) {
$value = $form_state
->getValue($entity_type);
if (empty($value)) {
$value = [];
}
$this
->config('exif.settings')
->set($entity_type, $value);
}
$this
->config('exif.settings')
->set('update_metadata', $form_state
->getValue('update_metadata', TRUE))
->set('write_empty_values', $form_state
->getValue('write_empty_values', FALSE))
->set('vocabulary', $form_state
->getValue('vocabulary', "0"))
->set('granularity', $form_state
->getValue('granularity'))
->set('date_format_exif', $form_state
->getValue('date_format_exif'))
->set('extraction_solution', $form_state
->getValue('extraction_solution'))
->set('exiftool_location', $form_state
->getValue('exiftool_location'))
->save();
parent::submitForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'exif.settings',
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
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 | |
ExifSettingsForm:: |
protected | property | The entity manager. | |
ExifSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
ExifSettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
ExifSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
ExifSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ExifSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
ExifSettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
ExifSettingsForm:: |
public | function |
Constructs the ExifSettingsForm object. Overrides ConfigFormBase:: |
|
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
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. | |
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. |