Commit 4d55a75d authored by ephoto_dam's avatar ephoto_dam

Ephoto Dam Field in progress

parent 3417e4ad
......@@ -6,7 +6,8 @@ core: '8.x'
core_version_requirement: ^8 || ^9
dependencies:
- drupal:ckeditor
- drupal:system
- drupal:system
configure: ephoto_dam.admin_settings
'interface translation project': ephoto_dam
'interface translation server pattern': modules/contrib/%project/translations/%language.po
......
ephoto_dam.admin_settings:
title: 'Ephoto Dam Settings'
route_name: ephoto_dam.admin_settings
description: 'Configure Ephoto Dam Module'
parent: system.admin_config
weight: 99
ephoto_dam.admin_settings:
path: '/admin/config/ephoto_dam'
defaults:
_form: '\Drupal\ephoto_dam\Form\ConfigurationForm'
_title: 'Configuration Form'
requirements:
_permission: 'administer site configuration'
......@@ -7,6 +7,7 @@ core_version_requirement: ^8 || ^9
dependencies:
- drupal:field
- drupal:system
configure: ephoto_dam.admin_settings
'interface translation project': ephoto_dam_field
'interface translation server pattern': modules/contrib/ephoto_dam/translations/%language.po
......
......@@ -15,11 +15,16 @@ use Drupal\Core\Url;
*/
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');
if ($field_definition->getType() === 'ephoto_dam_field') {
$element['#attached']['library'][] = 'ephoto_dam_field/edit';
$element['#attached']['drupalSettings']['ephotoDamField'] = $field_definition->getSettings();
$element['#attached']['drupalSettings']['ephotoDamField'] = $settings;
}
}
......
......@@ -41,7 +41,7 @@
* Enable version support
*/
enableVersionSupport: function(el) {
if(el.checked) {
if (el.checked) {
$('.ephoto-dam-field-version-field').removeClass('ephoto-dam-field-hidden');
$('.ephoto-dam-field-version-prefix').removeClass('ephoto-dam-field-hidden');
......@@ -62,6 +62,8 @@
* Load Ephoto Dam Api
*/
load: function() {
console.log(this.settings);
if (this.settings && this.settings.server_url) {
$.getScript(this.settings.server_url + '/api/apiJS.js', this.init.bind(this));
}
......
......@@ -91,19 +91,6 @@ class EphotoDamField extends FieldItemBase {
*/
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$form = [];
$form['server_url'] = [
'#title' => t('Server URL'),
'#type' => 'url',
'#default_value' => $this->getSetting('server_url'),
'#description' => t('Please enter the URL of your Ephoto Dam software'),
'#required' => true,
'#attributes' => [
'class' => ['form-text', 'ephoto-dam-field-settings-url'],
'placeholder' => t('https://ephoto.mycompany.com/')
],
'#size' => 50,
];
$form['version_support'] = [
'#title' => t('Version support'),
......@@ -124,7 +111,6 @@ class EphotoDamField extends FieldItemBase {
*/
public static function defaultFieldSettings() {
return [
'server_url' => '',
'version_support' => false
];
}
......
......@@ -58,16 +58,16 @@
*/
init: function (editor) {
var self = this;
this.settings = editor.config.ephoto_dam;
this.editor = editor;
if(!editor.ui.addButton || !this.settings.url) {
if(!editor.ui.addButton || !this.settings.server_url) {
return;
}
CKEDITOR.scriptLoader.load(this.settings.url + 'api/apiJS.js', this.initApi.bind(this));
CKEDITOR.scriptLoader.load(this.settings.server_url + 'api/apiJS.js', this.initApi.bind(this));
CKEDITOR.dialog.add('ephoto_dam_properties', this.getPropertiesBox);
......@@ -143,7 +143,7 @@
}
this.ephoto = new ePhoto({
'server': this.settings.url,
'server': this.settings.server_url,
'authID': CKEDITOR.tools.getCookie('drupal_ephoto_dam_authid'),
'client': this.CLIENT_ID
});
......
<?php
namespace Drupal\ephoto_dam\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class ConfigForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'ephoto_dam.adminsettings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ephoto_dam_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
error_log('build form');
$config = $this->config('welcome.adminsettings');
$form['ephoto_dam_form'] = [
'#type' => 'textarea',
'#title' => $this->t('Welcome message'),
'#description' => $this->t('Welcome message display to users when they login'),
'#default_value' => $config->get('ephoto_dam_form'),
];
return parent::buildForm($form, $form_state);
}
}
\ No newline at end of file
<?php
/**
* @file
* Contains \Drupal\ephoto_dam\Form\ConfigurationForm.
*/
namespace Drupal\ephoto_dam\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class ConfigurationForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'ephoto_dam.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ephoto_dam_admin_settings';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('ephoto_dam.settings');
$form['settings_server_url'] = [
'#title' => $this->t('Server URL'),
'#type' => 'url',
'#description' => $this->t('Please enter the URL of your Ephoto Dam software'),
'#default_value' => $config->get('server_url'),
'#required' => true,
'#attributes' => ['placeholder' => $this->t('https://ephoto.mycompany.com/')],
'#size' => 50,
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('ephoto_dam.settings')
->set('server_url', $form_state->getValue('settings_server_url'))
->save();
parent::submitForm($form, $form_state);
}
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ class EphotoDam extends CKEditorPluginBase implements CKEditorPluginConfigurable
* @const
*/
private const DEFAULT_SETTINGS = [
'url' => '',
'server_url' => '/',
'captions' => true,
'captions_format' => '[dc:rights]',
'zoom' => true,
......@@ -70,16 +70,6 @@ class EphotoDam extends CKEditorPluginBase implements CKEditorPluginConfigurable
$form['#attached']['library'][] = 'ephoto_dam/settings';
$form['url'] = [
'#title' => $this->t('Server URL'),
'#type' => 'url',
'#default_value' => $settings->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['captions'] = [
'#title' => $this->t('Captions'),
'#type' => 'checkbox',
......@@ -146,6 +136,7 @@ class EphotoDam extends CKEditorPluginBase implements CKEditorPluginConfigurable
*/
protected function getSettings($editor):array {
$editor_settings = $editor->getSettings();
$common_settings = \Drupal::config('ephoto_dam.settings');
$settings = NestedArray::getValue($editor_settings, [
'plugins',
......@@ -155,6 +146,8 @@ class EphotoDam extends CKEditorPluginBase implements CKEditorPluginConfigurable
if(!$settings) {
$settings = self::DEFAULT_SETTINGS;
}
$settings['server_url'] = $common_settings->get('server_url');
return $settings;
}
......
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