Commit 78421148 authored by ephoto_dam's avatar ephoto_dam

Ephoto Dam Field support

parent 00c86d14
.field--type-ephoto-dam-field .form-type-textfield {
float:left;
margin-right:5px;
float:left;
margin-right:5px;
}
.field--type-ephoto-dam-field .field-multiple-drag {
display:none;
display:none;
}
.field--type-ephoto-dam-field .tabledrag-toggle-weight-wrapper {
display:none;
display:none;
}
.ephoto-dam-field-import-button {
border-radius:2px !important;
margin:5px 0 0 0 !important;
padding-left:2.5em !important;
padding-right:1em !important;
background:#fff url(/modules/contrib/ephoto_dam/plugin/icon.png) 0.8em no-repeat !important;
display:block !important
.ephoto-dam-field-button {
border-radius:2em !important;
margin:5px 0 0 0 !important;
padding-left:2.5em !important;
padding-right:1em !important;
background:#fff url(/modules/contrib/ephoto_dam/plugin/icon.png) 0.8em no-repeat !important;
display:block !important
}
.ephoto-dam-field-field-button {
margin:26px 0 0 0 !important;
}
.ephoto-dam-field-hidden {
display:none !important
}
/*
.ephoto-dam-field-version-field {
float:left;
margin-right:5px;
margin-top:4px;
}
*/
/*
.ephoto-dam-field-value-field {
margin-top:-5px
}
*/
\ No newline at end of file
/**
* Ephoto Dam Addon for Drupal 9
*
* @base EPHOTO DAM
* @base EPHOTO DAM FIELD
* @author EINDEN
*/
(function ($) {
//alert('ok');
EPHOTO_DAM_FIELD = {
enableVersionSupport: function(el) {
if(el.checked) {
$('.ephoto-dam-field-version-field').removeClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-version-button').removeClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-field-button').addClass('ephoto-dam-field-hidden');
}
else {
$('.ephoto-dam-field-version-field').addClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-version-button').addClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-field-button').removeClass('ephoto-dam-field-hidden');
}
}
};
})(jQuery);
......@@ -18,13 +18,6 @@ use Drupal\Core\TypedData\TraversableTypedDataInterface;
* category = @Translation("Media"),
* default_widget = "ephoto_dam_field_widget",
* )
*
* default_formatter = "ephoto_dam_field_format", => formatage du champ pour l'affichage, pas d'intérêt dans notre cas
* constraints = {"EphotoDamValidation" = {}} => méthode de vérification du formatage des valeurs. Permet l'affichage d'un message d'erreur s'il manque des variantes
*
* https://www.lullabot.com/articles/extending-a-field-type-in-drupal-8
*
* https://www.drupal.org/project/drupal/issues/2264739
*/
class EphotoDamField extends FieldItemBase {
......@@ -58,21 +51,12 @@ class EphotoDamField extends FieldItemBase {
]
]
];
}
/**
* {@inheritdoc}
*/
public function getFile() {
return drupal_get_path('module', 'ephoto_dam') . '/plugin/plugin.js';
}
}
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
// https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21TypedData%21DataDefinition.php/class/DataDefinition/8.2.x
$properties['value'] = DataDefinition::create('string')
->setLabel(t('Url'))
//->setRequired(true)
......@@ -81,7 +65,7 @@ class EphotoDamField extends FieldItemBase {
$properties['version'] = DataDefinition::create('string')
->setLabel(t('Version'))
//->setRequired(true)
->setRequired(true)
;
return $properties;
......@@ -101,17 +85,15 @@ class EphotoDamField extends FieldItemBase {
* {@inheritdoc}
*/
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
/*
$form['allowed_providers'] = [
'#title' => $this->t('Allowed Providers'),
'#description' => $this->t('Restrict users from entering information from the following providers. If none are selected any video provider can be used.'),
'#type' => 'markup',
//'#default_value' => $this->getSetting('allowed_providers'),
//'#options' => $this->providerManager->getProvidersOptionList(),
$form['version_support'] = [
'#title' => $this->t('Version support'),
'#description' => $this->t('An url will be automatically associated with each version with the same name in Ephoto Dam') . '.',
'#type' => 'checkbox',
'#default_value' => $this->getSetting('version_support'),
'#attributes' => [
'onclick' => 'EPHOTO_DAM_FIELD.enableVersionSupport(this)'
]
];
*/
$form = [];
return $form;
}
......@@ -120,12 +102,8 @@ class EphotoDamField extends FieldItemBase {
* {@inheritdoc}
*/
public static function defaultFieldSettings() {
// Valeurs par défaut du formulaire de configuration
// Accessible depuis le widget via getFieldSetting()
return [
//'allowed_providers' => [],
'version_support' => false
];
}
}
}
......@@ -25,66 +25,65 @@ class EphotoDamFieldWidget extends WidgetBase {
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
//$default_value = isset($items[$delta]->value) ? $items[$delta]->value : null;
// https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Field%21WidgetBase.php/class/WidgetBase/8.2.x
// https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Field%21FieldDefinition.php/class/FieldDefinition/8.7.x
// $this->getFieldSetting('max_length')
// $this->getFieldSettings()
// $this->fieldDefinition->getName()
// $items[$delta]->getName()
//error_log(var_export($items[$delta]->getName(), true));
//error_log(var_export($this->fieldDefinition->getName(), true));
//if(0 === $items[$delta]->getName()) {
$is_default_values_form = $this->isDefaultValueWidget($form_state);
$version_support = $this->getFieldSetting('version_support');
// #field-ephoto-values .form-item { float:left }
if (self::$first) {
$classes = ['ephoto-dam-field-button', 'ephoto-dam-field-version-button'];
if (!$version_support) $classes[] = 'ephoto-dam-field-hidden';
if(self::$first) {
$element['import'] = [
$element['version-import'] = [
'#type' => 'button',
'#value' => $this->t('Import'),
'#attributes' => [
'class' => ['form-url'],
'class' => $classes,
'onclick' => 'alert("Import!");return false',
'class' => ['ephoto-dam-field-import-button']
'class' => $classes
]
];
self::$first = false;
}
$default_value = isset($items[$delta]->value) ? $items[$delta]->value : null;
$default_version = isset($items[$delta]->version) ? $items[$delta]->version : null;
$element['value'] = [
'#type' => 'textfield',
'#title' => $this->t('URL') . ' ' . ($delta + 1),
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : null,
'#size' => 100,
'#maxlength' => 256,
'#disabled' => $is_default_values_form,
'#attributes' => [
'class' => ['form-url', 'ephoto-dam-field-value-field'],
]
];
$classes = ['form-url', 'ephoto-dam-field-version-field'];
if (!$version_support) $classes[] = 'ephoto-dam-field-hidden';
$element['version'] = [
'#type' => 'textfield',
'#title' => $this->t('Version') . ' ' . $items[$delta]->getName(),
//'#title_display' => 'after',
'#default_value' => $default_version,
'#title' => ' ',
'#default_value' => isset($items[$delta]->version) ? $items[$delta]->version : null,
'#size' => 20,
'#maxlength' => 60,
'#attributes' => [
'class' => ['form-url', 'ephoto-dam-field-version-field'],
//'style' => 'float:left;margin-right:5px;margin-top:4px'
'class' => $classes,
'placeholder' => $this->t('Version name')
]
];
];
$classes = ['ephoto-dam-field-button', 'ephoto-dam-field-field-button'];
if ($version_support) $classes[] = 'ephoto-dam-field-hidden';
$element['value'] = [
'#type' => 'textfield',
'#title' => $this->t('URL'),
'#default_value' => $default_value,
'#size' => 60,
'#maxlength' => 256,
$element['field-import'] = [
'#type' => 'button',
'#value' => $this->t('Import'),
'#attributes' => [
'class' => ['form-url', 'ephoto-dam-field-value-field'],
//'style' => 'margin-top:-5px'
]
];
'class' => $classes,
'onclick' => 'alert("Import!");return false',
'class' => $classes
]
];
return $element;
}
......
......@@ -64,7 +64,6 @@ class EphotoDam extends CKEditorPluginBase implements CKEditorPluginConfigurable
/**
* {@inheritdoc}
* Méthode appelé à l'édition de la barre d'enrichissement. Injecte le formulaire de configuration
*/
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
$settings = (object) $this->getSettings($editor);
......
......@@ -9,7 +9,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: fr\n"
"X-Generator: Poedit 2.2.4\n"
"X-Generator: Poedit 2.4.1\n"
"X-Poedit-SourceCharset: UTF-8\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
......@@ -99,3 +99,15 @@ msgstr "Droit"
msgid "Caption"
msgstr "Légende"
msgid "Version name"
msgstr "Nom de la version"
msgid "URL"
msgstr "URL"
msgid "An url will be automatically associated with each version with the same name in Ephoto Dam"
msgstr "Une url sera automatiquement associée à chaque version du même nom dans Ephoto Dam"
msgid "Versions support"
msgstr "Prise en charge des versions"
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