diff --git a/modules/ephoto_dam_field/js/ephoto_dam_field.js b/modules/ephoto_dam_field/js/ephoto_dam_field.js index 918c46a6c3412ad99dea68f3028eb6d926b8f953..cf5e6d52fed238f783b07664c6c764eff4be69b0 100644 --- a/modules/ephoto_dam_field/js/ephoto_dam_field.js +++ b/modules/ephoto_dam_field/js/ephoto_dam_field.js @@ -86,13 +86,7 @@ this.ephoto.connect(); - if (this.settings.version_support === '1') { - this.ephoto.File.callOnFileReceived(this.getVersionUrls.bind(this)); - } - - else { - this.ephoto.File.callOnFileReceived(this.getFileUrl.bind(this)); - } + this.ephoto.File.callOnFileReceived(this.getUrl.bind(this)); this.ephoto.File.setMode('manual'); @@ -123,18 +117,11 @@ this.ephoto.File.get(); }, - - /** - * - */ - getVersionUrls: function() { - console.log('get version urls!'); - }, /** * */ - select: function(delta) { + selectFile: function(delta) { this.fieldSelected = this._getFieldValues()[delta]; if (!this.fieldSelected) { @@ -156,17 +143,18 @@ /** * */ - getFileUrl: function() { - console.log('get file url!'); + getUrl: function() { + var self = this; + var version_support = this.settings.version_support === '1'; - if (!this._fieldSelected) { + if (!this.fieldSelected) { alert(Drupal.t('Field selection error')); return; } - this.ephoto.File.store(function(url) { - this._fieldSelected.value = url; - this._fieldSelected = null; + this.ephoto.File.store(function(url) { + self.fieldSelected.input.val(url); + self.fieldSelected = null; }); }, @@ -176,11 +164,13 @@ _getFieldValues: function() { var fields = []; var sizes = $('.ephoto-dam-field-imagesize-field').toArray(); + var inputs = $('.ephoto-dam-field-value-field').toArray(); $('.ephoto-dam-field-version-field').map(function(index, el) { fields.push({ 'name' : $(el).val(), - 'size' : $(sizes[index]).val() + 'size' : $(sizes[index]).val(), + 'input' : $(inputs[index]) }); }); diff --git a/modules/ephoto_dam_field/src/Plugin/Field/FieldType/EphotoDamField.php b/modules/ephoto_dam_field/src/Plugin/Field/FieldType/EphotoDamField.php index 0f0ec9a2cc5960c2a8234d2fad91cd6ccb145653..e4d504b3992394dcd22fb82d0c1ff01914650cd7 100644 --- a/modules/ephoto_dam_field/src/Plugin/Field/FieldType/EphotoDamField.php +++ b/modules/ephoto_dam_field/src/Plugin/Field/FieldType/EphotoDamField.php @@ -63,16 +63,16 @@ class EphotoDamField extends FieldItemBase { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') - ->setLabel(t('Url')) - ->setRequired(true); + ->setLabel(t('Url')); + //->setRequired(true); $properties['image_size'] = DataDefinition::create('integer') - ->setLabel(t('Image size')) - ->setRequired(true); + ->setLabel(t('Image size')); + //->setRequired(true); $properties['version'] = DataDefinition::create('string') - ->setLabel(t('Version')) - ->setRequired(true); + ->setLabel(t('Version')); + //->setRequired(true); return $properties; } @@ -92,6 +92,8 @@ class EphotoDamField extends FieldItemBase { * {@inheritdoc} */ public function fieldSettingsForm(array $form, FormStateInterface $form_state) { + $form = []; + $form['server_url'] = [ '#title' => $this->t('Server URL'), '#type' => 'url', diff --git a/modules/ephoto_dam_field/src/Plugin/Field/FieldWidget/EphotoDamFieldWidget.php b/modules/ephoto_dam_field/src/Plugin/Field/FieldWidget/EphotoDamFieldWidget.php index 96552d623bc20144465a3823c5f7fff0c5143c20..97734fe231fe173989d2769933b5a2bdbdcadc5d 100644 --- a/modules/ephoto_dam_field/src/Plugin/Field/FieldWidget/EphotoDamFieldWidget.php +++ b/modules/ephoto_dam_field/src/Plugin/Field/FieldWidget/EphotoDamFieldWidget.php @@ -38,7 +38,7 @@ class EphotoDamFieldWidget extends WidgetBase { '#disabled' => $is_default_values_form, '#attributes' => [ 'class' => $classes, - 'onclick' => 'Drupal.ephotoDamField.selectVersionUrls();return false', + 'onclick' => 'Drupal.ephotoDamField.selectVersions();return false', 'class' => $classes, ], ]; @@ -61,7 +61,7 @@ class EphotoDamFieldWidget extends WidgetBase { $element['image_size'] = [ '#type' => 'number', '#title' => ' ', - '#default_value' => isset($items[$delta]->image_size) ? $items[$delta]->image_size : 0, + '#default_value' => isset($items[$delta]->image_size) ? $items[$delta]->image_size : null, '#disabled' => !$is_default_values_form, '#size' => 12, '#maxlength' => 60, @@ -69,7 +69,6 @@ class EphotoDamFieldWidget extends WidgetBase { '#attributes' => [ 'class' => ['form-url', 'ephoto-dam-field-imagesize-field'], 'placeholder' => $this->t('Image size'), - 'min' => 20, 'max' => 1600 ] ]; @@ -99,7 +98,7 @@ class EphotoDamFieldWidget extends WidgetBase { '#disabled' => $is_default_values_form, '#attributes' => [ 'class' => $classes, - 'onclick' => 'Drupal.ephotoDamField.selectUrl(' . $delta . ');return false', + 'onclick' => 'Drupal.ephotoDamField.selectFile(' . $delta . ');return false', 'class' => $classes ] ];