Commit 51af3b2d authored by ephoto_dam's avatar ephoto_dam

Ephoto D

parent dd955abf
......@@ -8,3 +8,4 @@ edit:
header: true
dependencies:
- core/jquery
- core/jquery.cookie
......@@ -15,20 +15,8 @@ function ephoto_dam_field_field_widget_form_alter(&$element, &$form_state, $cont
$field_definition = $context['items']->getFieldDefinition();
if ($field_definition->getType() === 'ephoto_dam_field') {
$settings = $field_definition->getSettings();
$settings_encoded = str_replace('"', "'", Json::encode($settings));
$element['#attached']['library'][] = 'ephoto_dam_field/edit';
// I do not like it
// It would be nice to put the settings AFTER the ".libraries", which would make it possible to call directly EphotoDamField.load($settings_encoded)
$element['#attached']['html_head'][] = [
[
'#tag' => 'script',
'#value' => Markup::create('EphotoDamFieldSettings=' . $settings_encoded . ';'),
'#weight' => 200
],
'ephoto_dam_field_js_settings'
];
$element['#attached']['drupalSettings']['ephotoDamField'] = $field_definition->getSettings();
}
}
......@@ -6,7 +6,7 @@
*/
(function ($) {
EphotoDamField = {
Drupal.ephotoDamField = {
/**
* EPHOTO ID of Drupal Addon
*/
......@@ -15,7 +15,7 @@
/**
* Settings
*/
settings: null,
settings: drupalSettings.ephotoDamField,
/**
* Ephoto Dam instance
......@@ -50,28 +50,32 @@
* Load Ephoto Dam Api
*/
load: function() {
this.settings = EphotoDamFieldSettings;
$.getScript(settings.url + 'api/apiJS.js', this.initApi.bind(this));
$.getScript(this.settings.url + 'api/apiJS.js', this.init.bind(this));
},
/**
* Init Ephoto Dam Api
*/
initApi: function() {
init: function() {
var self = this;
//console.log(Drupal.attachBehaviors);
/*
Drupal.attachBehaviors(context, settings) {
console.log(settings);
};
*/
if (!ePhoto) {
console.log(Drupal.t('Error loading the Ephoto Dam API'));
return;
}
console.log('loaded!');
console.log(this.settings.url);
this.ephoto = new ePhoto({
'server': this.settings.url,
//'authID': CKEDITOR.tools.getCookie('drupal_ephoto_dam_authid'),
'authID': $.cookie('drupal_ephoto_dam_authid'),
'client': this.CLIENT_ID
});
......@@ -82,13 +86,10 @@
//this.ephoto.File.enableDCore();
this.ephoto.callOnConnect(function() {
//var today = expires = new Date();
//expires.setDate(today.getDate() + 2);
$.cookie('drupal_ephoto_dam_authid', self.ephoto.getAuthID(), { path:'/' });
//CKEDITOR.tools.setCookie( 'drupal_ephoto_dam_authid', self.ephoto.getAuthID());
self.connected = true;
self.connected = true;
});
this.ephoto.File.callOnFileReceived(this.insert.bind(this));
......@@ -116,6 +117,6 @@
}
}
EphotoDamField.load();
})(jQuery);
Drupal.ephotoDamField.load();
......@@ -21,100 +21,100 @@ use Drupal\Core\TypedData\TraversableTypedDataInterface;
*/
class EphotoDamField extends FieldItemBase {
/**
* {@inheritdoc}
*/
public function __construct($definition, $name = NULL, TraversableTypedDataInterface $parent = NULL) {
parent::__construct($definition, $name, $parent);
}
/**
* {@inheritdoc}
*/
public function __construct($definition, $name = NULL, TraversableTypedDataInterface $parent = NULL) {
parent::__construct($definition, $name, $parent);
}
/**
* {@inheritdoc}
*/
public static function createInstance($definition, $name = NULL, TraversableTypedDataInterface $parent = NULL) {
return new static($definition, $name, $parent);
}
/**
* {@inheritdoc}
*/
public static function createInstance($definition, $name = NULL, TraversableTypedDataInterface $parent = NULL) {
return new static($definition, $name, $parent);
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'type' => 'varchar',
'length' => 256
],
'version' => [
'type' => 'varchar',
'length' => 20
]
]
];
}
/**
* {@inheritdoc}
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return [
'columns' => [
'value' => [
'type' => 'varchar',
'length' => 256
],
'version' => [
'type' => 'varchar',
'length' => 20
]
]
];
}
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string')
->setLabel(t('Url'))
//->setRequired(true)
//->setDescription(t('The node UUID.'))
;
/**
* {@inheritdoc}
*/
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string')
->setLabel(t('Url'))
//->setRequired(true)
//->setDescription(t('The node UUID.'))
;
$properties['version'] = DataDefinition::create('string')
->setLabel(t('Version'))
->setRequired(true)
;
return $properties;
}
$properties['version'] = DataDefinition::create('string')
->setLabel(t('Version'))
->setRequired(true)
;
return $properties;
}
/**
* {@inheritdoc}
*/
public function isEmpty() {
$value = $this->get('value')->getValue();
$version = $this->get('version')->getValue();
/**
* {@inheritdoc}
*/
public function isEmpty() {
$value = $this->get('value')->getValue();
$version = $this->get('version')->getValue();
return empty($value) && empty($version);
}
return empty($value) && empty($version);
}
/**
* {@inheritdoc}
*/
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$form['url'] = [
'#title' => $this->t('Server URL'),
'#type' => 'url',
'#default_value' => $this->getSetting('url'),
'#description' => $this->t('Please enter the URL of your Ephoto Dam software'),
'#required' => true,
'#attributes' => ['placeholder' => $this->t('https://ephoto.mycompany.com/')],
'#size' => 50,
];
$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' => 'EphotoDamField.enableVersionSupport(this)'
]
];
/**
* {@inheritdoc}
*/
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$form['url'] = [
'#title' => $this->t('Server URL'),
'#type' => 'url',
'#default_value' => $this->getSetting('url'),
'#description' => $this->t('Please enter the URL of your Ephoto Dam software'),
'#required' => true,
'#attributes' => ['placeholder' => $this->t('https://ephoto.mycompany.com/')],
'#size' => 50,
];
$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' => 'Drupal.ephotoDamField.enableVersionSupport(this)'
]
];
return $form;
}
return $form;
}
/**
* {@inheritdoc}
*/
public static function defaultFieldSettings() {
return [
'url' => '',
'version_support' => false
];
}
/**
* {@inheritdoc}
*/
public static function defaultFieldSettings() {
return [
'url' => '',
'version_support' => false
];
}
}
......@@ -5,7 +5,6 @@ namespace Drupal\ephoto_dam_field\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Component\Serialization\Json;
/**
* Ephoto Dam Widget
......@@ -20,76 +19,75 @@ use Drupal\Component\Serialization\Json;
*/
class EphotoDamFieldWidget extends WidgetBase {
static bool $first = true;
static bool $first = true;
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$is_default_values_form = $this->isDefaultValueWidget($form_state);
$version_support = $this->getFieldSetting('version_support');
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$is_default_values_form = $this->isDefaultValueWidget($form_state);
$version_support = $this->getFieldSetting('version_support');
if (self::$first) {
$classes = ['ephoto-dam-field-button', 'ephoto-dam-field-version-button'];
if (!$version_support) $classes[] = 'ephoto-dam-field-hidden';
if (self::$first) {
$classes = ['ephoto-dam-field-button', 'ephoto-dam-field-version-button'];
if (!$version_support) $classes[] = 'ephoto-dam-field-hidden';
$element['version-import'] = [
'#type' => 'button',
'#value' => $this->t('Select'),
'#disabled' => $is_default_values_form,
'#attributes' => [
'class' => $classes,
'onclick' => 'EphotoDamField.selectVersionUrls();return false',
'class' => $classes,
],
];
$element['version-import'] = [
'#type' => 'button',
'#value' => $this->t('Select'),
'#disabled' => $is_default_values_form,
'#attributes' => [
'class' => $classes,
'onclick' => 'Drupal.ephotoDamField.selectVersionUrls();return false',
'class' => $classes,
],
];
self::$first = false;
}
$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'],
]
];
self::$first = false;
}
$classes = ['form-url', 'ephoto-dam-field-version-field'];
if (!$version_support) $classes[] = 'ephoto-dam-field-hidden';
$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'],
]
];
$element['version'] = [
'#type' => 'textfield',
'#title' => ' ',
'#default_value' => isset($items[$delta]->version) ? $items[$delta]->version : null,
'#disabled' => !$is_default_values_form,
'#size' => 20,
'#maxlength' => 60,
'#attributes' => [
'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';
$classes = ['form-url', 'ephoto-dam-field-version-field'];
if (!$version_support) $classes[] = 'ephoto-dam-field-hidden';
$element['field-import'] = [
'#type' => 'button',
'#value' => $this->t('Import'),
'#disabled' => $is_default_values_form,
'#attributes' => [
'class' => $classes,
'onclick' => 'EphotoDamField.selectUrl(' . $delta . ');return false',
'class' => $classes
]
];
$element['version'] = [
'#type' => 'textfield',
'#title' => ' ',
'#default_value' => isset($items[$delta]->version) ? $items[$delta]->version : null,
'#disabled' => !$is_default_values_form,
'#size' => 20,
'#maxlength' => 60,
'#attributes' => [
'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';
return $element;
}
$element['field-import'] = [
'#type' => 'button',
'#value' => $this->t('Import'),
'#disabled' => $is_default_values_form,
'#attributes' => [
'class' => $classes,
'onclick' => 'Drupal.ephotoDamField.selectUrl(' . $delta . ');return false',
'class' => $classes
]
];
return $element;
}
}
......@@ -155,10 +155,6 @@
this.ephoto.File.enableDCore();
this.ephoto.callOnConnect(function() {
var today = expires = new Date();
expires.setDate(today.getDate() + 2);
CKEDITOR.tools.setCookie( 'drupal_ephoto_dam_authid', self.ephoto.getAuthID());
self.connected = true;
......
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