Commit cda14bcf authored by Arnaud Bour's avatar Arnaud Bour

Ephoto Dam Field in progress

parent af1f864f
This diff is collapsed.
......@@ -7,6 +7,7 @@ core_version_requirement: ^8 || ^9
dependencies:
- drupal:field
- drupal:system
- ephoto_dam:ephoto_dam
configure: ephoto_dam.admin_settings
'interface translation project': ephoto_dam_field
......
......@@ -6,6 +6,7 @@
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Serialization\Json;
use \Drupal\Core\Render\Markup;
use Drupal\Core\Url;
......@@ -14,12 +15,13 @@ use Drupal\Core\Url;
* Hook : implements hook_field_widget_form_alter().
*/
function ephoto_dam_field_field_widget_form_alter(&$element, &$form_state, $context) {
$field_definition = $context['items']->getFieldDefinition();
$common_settings = \Drupal::config('ephoto_dam.settings');
$settings = $field_definition->getSettings();
$settings['server_url'] = $common_settings->get('server_url');
$common_settings = \Drupal::config('ephoto_dam.settings');
$settings = $field_definition->getSettings();
$settings['server_url'] = $common_settings->get('server_url');
if ($field_definition->getType() === 'ephoto_dam_field') {
$element['#attached']['library'][] = 'ephoto_dam_field/edit';
......@@ -30,23 +32,51 @@ function ephoto_dam_field_field_widget_form_alter(&$element, &$form_state, $cont
/**
* Hook : implements hook_help().
* Méthode appelé à l'affichage de la page d'aide
*/
function ephoto_dam_field_help($route_name, RouteMatchInterface $route_match) {
if ($route_name !== 'help.page.ephoto_dam_field') {
return;
}
$links = [
':field_ui_help' => Url::fromRoute('help.page', ['name' => 'field'])->toString(),
':field_help' => \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#'
];
$output = '<h3>' . t('Ephoto Dam Field help') . '</h3>';
$output .= '<p>';
if ($route_name !== 'help.page.ephoto_dam_field') {
return;
}
$links = [
':field_ui_help' => Url::fromRoute('help.page', ['name' => 'field'])->toString(),
':field_help' => \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#'
];
$output = '<h3>' . t('Ephoto Dam Field help') . '</h3>';
$output .= '<p>';
$output .= t('The Ephoto Dam module provides a field type') . '<br>';
$output .= t('See the <a href=":field_help">Field module help</a> and the <a href=":field_ui_help">Field UI help</a> pages for general information on fields and how to create and manage them.', $links);
$output .= t('See the <a href=":field_help">Field module help</a> and the <a href=":field_ui_help">Field UI help</a> pages for general information on fields and how to create and manage them.', $links);
$output .= '</p>';
return $output;
return $output;
}
/**
* Hook : implements hook_form_FORM_ID_alter().
*/
function ephoto_dam_field_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id === 'field_config_edit_form') {
$form['#validate'][] = 'ephoto_dam_field_settings_validate';
}
}
/**
* Hook : implements hook_settings_validate().
*/
function ephoto_dam_field_settings_validate($form, FormStateInterface $form_state) {
$common_settings = \Drupal::config('ephoto_dam.settings');
$server_url = $common_settings->get('server_url');
$links = [
':config_ephoto_dam' => '/admin/config/ephoto_dam'
];
if (!$server_url) {
$form_state->setError( $form, t('Please enter the server URL first from the <a href=":config_ephoto_dam">module configuration form</a>', $links) );
}
}
......@@ -5,8 +5,6 @@ namespace Drupal\ephoto_dam_field\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
/**
* Validation constraint for the ephoto dam field.
*
* @Constraint(
* id = "EphotoDamFieldValidation"
* )
......
......@@ -33,9 +33,9 @@ class EphotoDamFieldConstraintValidator extends ConstraintValidator implements C
return NULL;
}
$test1 = preg_match('/^[0-9x]+$/', $field->image_size);
$message1 = t('The "Size" field must respect one of the following patterns: "x{height}", "{width}x", "{width}x{height}" or "{width/height (detect auto)}". Examples: "x500", "500x", "500x500" or "500".');
$test = preg_match('/^[0-9x]+$/', $field->image_size);
$message = t('The "Size" field must respect one of the following patterns: "x{height}", "{width}x", "{width}x{height}" or "{width/height (detect auto)}". Examples: "x500", "500x", "500x500" or "500".');
if (!$test1) $this->context->addViolation($message1);
if (!$test) $this->context->addViolation($message);
}
}
......@@ -49,6 +49,18 @@ class ConfigurationForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$server_url = $form_state->getValue('settings_server_url');
$server_url = filter_var($server_url, FILTER_VALIDATE_URL);
if (!$server_url) {
$form_state->setErrorByName('settings_server_url', t('Please enter a correct URL') );
}
if (substr($server_url, -1) !== '/') {
$server_url .= '/';
}
parent::validateForm($form, $form_state);
}
......
......@@ -29,7 +29,7 @@ class EphotoDam extends FilterBase implements ContainerFactoryPluginInterface {
'align',
'src',
'embed',
'width',
'width',
'height',
'alt',
'caption',
......@@ -71,8 +71,6 @@ class EphotoDam extends FilterBase implements ContainerFactoryPluginInterface {
$text = str_replace($source, $html, $text);
$result->setAttachments(['library' => ['ephoto_dam/display']]);
//$response->setCacheContexts(['user.permissions']);
}
$result->setProcessedText($text);
......@@ -185,7 +183,13 @@ class EphotoDam extends FilterBase implements ContainerFactoryPluginInterface {
return false;
}
}
$common_settings = \Drupal::config('ephoto_dam.settings');
if ($common_settings->get('server_url')) {
return false;
}
return true;
}
}
......@@ -131,4 +131,7 @@ msgid "The version of Ephoto Dam is not compatible with this feature"
msgstr "La version d'Ephoto Dam n'est pas compatible avec cette fonctionnalité"
msgid "Legend"
msgstr "Légende"
\ No newline at end of file
msgstr "Légende"
msgid "Please enter the server URL first from the <a href=\":config_ephoto_dam\">module configuration form</a>"
msgstr "Veuillez d'abord saisir l'URL du serveur à partir du <a href=\":config_ephoto_dam\">formulaire de configuration du module</a>"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment