Commit afbe6a2f authored by ephoto_dam's avatar ephoto_dam

ephoto_dam_field support in progress

parent 07ebb40f
/**
* Ephoto Dam Addon for Drupal 9
*
* @base EPHOTO DAM
* @author EINDEN - Tous droits réservés
*/
.ephoto-dam-align-center {
margin-right: auto;
margin-left: auto;
......
......@@ -8,10 +8,3 @@ display:
header: true
dependencies:
- core/jquery
settings:
version: 1.x
css:
component:
plugin/plugin.css: {}
header: true
......@@ -15,7 +15,6 @@ use Drupal\Core\Url;
* Méthode appelé pour ajouter le css du plugin CkEditor
*/
function ephoto_dam_ckeditor_css_alter(array &$css, Editor $editor) {
$css[] = drupal_get_path('module', 'ephoto_dam') . '/plugin/plugin.css';
}
......@@ -24,7 +23,6 @@ function ephoto_dam_ckeditor_css_alter(array &$css, Editor $editor) {
* Méthode appelé à la configuration des barres d'enrichissement
*/
function ephoto_dam_form_filter_format_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Appel de la méthode ephoto_dam_toolbar_filter_validate()
$form['#validate'][] = 'ephoto_dam_toolbar_filter_validate';
......
......@@ -2,11 +2,10 @@
* Ephoto Dam Addon for Drupal 9
*
* @base EPHOTO DAM
* @author EINDEN - Tous droits réservés
* @author EINDEN
*/
(function ($) {
var EphotoDam = {
zoomIn: function(img) {
var overlay = $('#ephoto-dam-overlay').length ? $('#ephoto-dam-overlay'): $('<div id="ephoto-dam-overlay"></div>').appendTo('body');
......
#field-ephoto-values .form-item {
float:left;
}
......@@ -6,7 +6,7 @@ core: '8.x'
core_version_requirement: ^8 || ^9
dependencies:
- drupal:field
- drupal:system
- drupal:system
'interface translation project': ephoto_dam
'interface translation server pattern': modules/%project/translations/%language.po
......
edit:
version: 1.x
js:
js/ephoto_dam_field.js: {}
css:
component:
css/ephoto_dam_field.css: {}
header: true
dependencies:
- core/jquery
......@@ -5,3 +5,9 @@
* Module ephoto_dam_field.
*/
/**
* Hook : implements hook_field_widget_form_alter().
*/
function ephoto_dam_field_field_widget_form_alter(&$element, &$form_state, $context) {
$element['#attached']['library'][] = 'ephoto_dam_field/edit';
}
/**
* Ephoto Dam Addon for Drupal 9
*
* @base EPHOTO DAM
* @author EINDEN
*/
(function ($) {
//alert('ok');
})(jQuery);
......@@ -12,6 +12,8 @@ use Drupal\Core\Session\AccountInterface;
use Drupal\field\Entity\FieldConfig;
use Symfony\Component\DependencyInjection\ContainerInterface;
// https://happyculture.coop/blog/drupal-8-creer-un-formateur-de-champ
/**
* Plugin implementation of the Ephoto Dam field formatter
*
......@@ -42,17 +44,9 @@ class EphotoDamFieldFormat extends FormatterBase implements ContainerFactoryPlug
* The view mode.
* @param array $third_party_settings
* Third party settings.
* @param \Drupal\video_embed_field\ProviderManagerInterface $provider_manager
* The video embed provider manager.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The logged in user.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, $settings, $label, $view_mode, $third_party_settings) {
//, ProviderManagerInterface $provider_manager, AccountInterface $current_user
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
//$this->providerManager = $provider_manager;
//$this->currentUser = $current_user;
}
/**
......@@ -67,9 +61,6 @@ class EphotoDamFieldFormat extends FormatterBase implements ContainerFactoryPlug
$configuration['label'],
$configuration['view_mode'],
$configuration['third_party_settings']
//$container->get('video_embed_field.provider_manager'),
//$container->get('current_user')
);
}
......
......@@ -16,10 +16,15 @@ use Drupal\Core\TypedData\TraversableTypedDataInterface;
* label = @Translation("Ephoto Dam Field"),
* description = @Translation("Stores a Ephoto Dam URL and then outputs some embed code"),
* category = @Translation("Media"),
* default_formatter = "ephoto_dam_field_format",
* default_widget = "ephoto_dam_field_widget",
* )
* constraints = {"EphotoDamValidation" = {}}
*
* 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 {
......@@ -45,20 +50,41 @@ class EphotoDamField extends FieldItemBase {
'columns' => [
'value' => [
'type' => 'varchar',
'length' => 256,
'length' => 256
],
],
'version' => [
'type' => 'varchar',
'length' => 20
]
]
];
}
/**
* {@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);
->setLabel(t('Url'))
//->setRequired(true)
//->setDescription(t('The node UUID.'))
;
$properties['version'] = DataDefinition::create('string')
->setLabel(t('Version'))
//->setRequired(true)
;
return $properties;
return $properties;
}
/**
......@@ -66,24 +92,27 @@ class EphotoDamField extends FieldItemBase {
*/
public function isEmpty() {
$value = $this->get('value')->getValue();
return empty($value);
$version = $this->get('version')->getValue();
return empty($value) && empty($version);
}
/**
* {@inheritdoc}
*/
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$form = [];
/*
/*
$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' => 'checkboxes',
'#default_value' => $this->getSetting('allowed_providers'),
'#options' => $this->providerManager->getProvidersOptionList(),
'#type' => 'markup',
//'#default_value' => $this->getSetting('allowed_providers'),
//'#options' => $this->providerManager->getProvidersOptionList(),
];
*/
*/
$form = [];
return $form;
}
......@@ -91,7 +120,9 @@ class EphotoDamField extends FieldItemBase {
* {@inheritdoc}
*/
public static function defaultFieldSettings() {
// Valeurs accessible depuis le widget via getFieldSetting()
// Valeurs par défaut du formulaire de configuration
// Accessible depuis le widget via getFieldSetting()
return [
//'allowed_providers' => [],
];
......
......@@ -19,28 +19,73 @@ use Drupal\Core\Form\FormStateInterface;
*/
class EphotoDamFieldWidget extends WidgetBase {
static bool $first = true;
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$default_value = isset($items[$delta]->value) ? $items[$delta]->value : null;
//error_log(var_export($this->getFieldSetting('max_length'), true));
$element['value'] = $element + [
//$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()) {
// #field-ephoto-values .form-item { float:left }
if(self::$first) {
$element['import'] = [
'#type' => 'button',
'#value' => $this->t('Import'),
'#attributes' => [
'class' => ['form-url'],
'onclick' => 'alert("Import!");return false',
'style' => 'border-radius:2px;margin:5px 0 0 0;padding-left:2.5em;padding-right:1em;background:0.8em url(/' . drupal_get_path('module', 'ephoto_dam') . '/plugin/icon.png) no-repeat'
]
];
self::$first = false;
}
$default_value = isset($items[$delta]->value) ? $items[$delta]->value : null;
$default_version = isset($items[$delta]->version) ? $items[$delta]->version : null;
$element['version'] = [
'#type' => 'textfield',
'#title' => 'Version',
//'#title_display' => 'after',
'#default_value' => $default_version,
'#size' => 20,
'#maxlength' => 60,
'#attributes' => [
'class' => ['form-url ephoto-version-class'],
//'style' => 'float:left;margin-right:5px;margin-top:4px'
]
];
$element['value'] = [
'#type' => 'textfield',
'#title' => 'URL',
'#default_value' => $default_value,
'#size' => 60,
'#maxlength' => $this->getFieldSetting('max_length'),
'#maxlength' => 256,
'#attributes' => [
'class' => ['js-text-full', 'text-full']
]
];
// Ajouter un bouton type "image_button" avec un onclick
// https://api.drupal.org/api/drupal/elements/8.2.x
// https://www.drupal.org/forum/support/module-development-and-code-questions/2012-09-05/solvedform-api-attributes-onclick
'class' => ['form-url ephoto-value-class'],
//'style' => 'margin-top:-5px'
]
];
return $element;
}
......
#edit-editor-settings-plugins-ephoto-dam-url { width:350px }
#edit-editor-settings-plugins-ephoto-dam-captions-format { width:350px; height:50px; resize:none }
#edit-editor-settings-plugins-ephoto-dam-url {
width:350px
}
#edit-editor-settings-plugins-ephoto-dam-captions-format {
width:350px;
height:50px;
resize:none
}
.cke_widget_ephoto_dam > .cke_widget_element {
display: table;
......
......@@ -2,7 +2,7 @@
* Ephoto Dam Addon for Drupal 9
*
* @base EPHOTO DAM
* @author EINDEN - Tous droits réservés
* @author EINDEN
*/
(function ($) {
......
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