Commit 3417e4ad authored by ephoto_dam's avatar ephoto_dam

Ephoto Dam Field in progress

parent 17e7bf16
......@@ -42,40 +42,38 @@ function ephoto_dam_help($route_name, RouteMatchInterface $route_match) {
$links = [
':config' => '/admin/config',
':config_content_formats' => '/admin/config/content/formats',
':config_content_formats_add' => '/admin/config/content/formats/add',
':field_ui_help' => Url::fromRoute('help.page', ['name' => 'field'])->toString(),
':field_help' => \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#'
':config_content_formats_add' => '/admin/config/content/formats/add'
];
$output = '<h3>' . t('Ephoto Dam help') . '</h3>';
$output .= '<h4>' . t('Configuration for import media into an article') . '</h4>';
$output .= '<ul>';
$output = '<h3>' . t('Ephoto Dam Embed help') . '</h3>';
$output .= '<h4>' . t('Configuration') . '</h4>';
$output .= '<p><ul>';
$output .= '<li>' . t('Step 1- Click on the "<a href=":config">Configuration</a>" tab and then on the "<a href=":config_content_formats">Text formats and editors</a>" link to select and configure text editors.', $links) . '</li>';
$output .= '<li>' . t('Step 2- Click the "<a href=":config_content_formats_add">Add Text Format</a>" button to create and customize the text format. Enter the "Name", check the "Roles" and select "CKEditor" in the "Text editor" list.', $links) . '</li>';
$output .= '<li>' . t('Step 3- In the “Toolbar configuration” section, select the "Ephoto button" and drag and drop it into the active toolbar to add the button.') . '</li>';
$output .= '<li>' . t('Step 4- Configure the "CKEditor plugin":') . '<ul>';
$output .= '<li>' . t('"Server URL": enter your Ephoto Dam software URL.') . '</li>';
$output .= '<li>' . t('"Captions": check the setting to display captions under images, videos and documents.') . '</li>';
$output .= '<li>' . t('"Captions format": configure the dynamic construction rule for the legend') . '</li>';
$output .= '<li>' . t('"Zoom": check the option to activate the zoom.') . '</li>';
$output .= '<li>' . t('"Size of images, videos and documents": enter a size to define the display size of the corresponding media.') . '</li>';
$output .= '<li>' . t('"Server URL": enter your Ephoto Dam software URL.') . '</li>';
$output .= '<li>' . t('"Captions": check the setting to display captions under images, videos and documents.') . '</li>';
$output .= '<li>' . t('"Captions format": configure the dynamic construction rule for the legend') . '</li>';
$output .= '<li>' . t('"Zoom": check the option to activate the zoom.') . '</li>';
$output .= '<li>' . t('"Size of images, videos and documents": enter a size to define the display size of the corresponding media.') . '</li>';
$output .= '</ul></li>';
$output .= '<li>' . t('Step 5- In the "Enabled filters" list, Check the "Ephoto Dam" filter.') . '<br>';
$output .= '<strong>' . t('Note: If several filters are activated, the “Ephoto Dam” filter must be the first in the filter processing order for the configuration to be valid.') . '</strong></li>';
$output .= '<li>' . t('Step 6- Click on the “Save Configuration” button to validate the new text format.') . '</li>';
$output .= '</ul>';
$output .= '<br>';
$output .= '<strong>' . t('Note: Click on “Configure” button to update the text format configuration') . '</strong><br>';
$output .= '<br>';
$output .= '<li>' . t('Step 6- Click on the “Save Configuration” button to validate the new text format.') . '<br>';
$output .= '<strong>' . t('Note: Click on “Configure” button to update the text format configuration') . '</strong></li>';
$output .= '</ul></p>';
$output .= '<h4>' . t('Import media into an article') . '</h4>';
$output .= '<ul>';
$output .= '<p><ul>';
$output .= '<li>' . t('Step 1- "Edit tab", click "Ephoto Dam" button and log in to Ephoto Dam.') . '</li>';
$output .= '<li>' . t('Step 2- Search and select media to import.') . '</li>';
$output .= '<li>' . t('Step 3- Click on “Import” to insert the media in the article body.') . '</li>';
$output .= '</ul>';
$output .= '<br>';
$output .= '<h4>' . t('The Ephoto Dam module provides a field type') . '</h4>';
$output .= '<p>' . t('See the <a href=":field_help">Field module help</a> and the <a href=":field_ui_help">Field UI help</a> pages for general information on fields and how to create and manage them.', $links) . '</p>';
$output .= '</ul></p>';
return $output;
}
......
.field--type-ephoto-dam-field .form-type-textfield {
float:left;
display:inline-block;
}
.field--type-ephoto-dam-field .field-multiple-drag {
......@@ -30,12 +30,12 @@
}
.ephoto-dam-field-url-suffix, .ephoto-dam-field-imagesize-suffix {
padding-right:10px
padding-right:0
}
.ephoto-dam-field-button {
border-radius:2em !important;
margin:5px 0 0 0 !important;
margin:0.5em 0 0 0 !important;
padding-left:2.5em !important;
padding-right:1em !important;
background:#f2f1eb url(/modules/contrib/ephoto_dam/plugin/icon.png) 0.8em no-repeat !important;
......
......@@ -5,8 +5,10 @@
* Module ephoto_dam_field.
*/
use Drupal\Component\Serialization\Json;
use \Drupal\Core\Render\Markup;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Component\Serialization\Json;
use \Drupal\Core\Render\Markup;
use Drupal\Core\Url;
/**
* Hook : implements hook_field_widget_form_alter().
......@@ -20,3 +22,26 @@ function ephoto_dam_field_field_widget_form_alter(&$element, &$form_state, $cont
$element['#attached']['drupalSettings']['ephotoDamField'] = $field_definition->getSettings();
}
}
/**
* Hook : implements hook_help().
* Méthode appelé à l'affichage de la page d'aide
*/
function ephoto_dam_field_help($route_name, RouteMatchInterface $route_match) {
if ($route_name !== 'help.page.ephoto_dam_field') {
return;
}
$links = [
':field_ui_help' => Url::fromRoute('help.page', ['name' => 'field'])->toString(),
':field_help' => \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#'
];
$output = '<h3>' . t('Ephoto Dam Field help') . '</h3>';
$output .= '<p>';
$output .= t('The Ephoto Dam module provides a field type') . '<br>';
$output .= t('See the <a href=":field_help">Field module help</a> and the <a href=":field_ui_help">Field UI help</a> pages for general information on fields and how to create and manage them.', $links);
$output .= '</p>';
return $output;
}
<?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
......@@ -19,173 +19,173 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class EphotoDam extends FilterBase implements ContainerFactoryPluginInterface {
/**
* Default settings
*
* @const
*/
private const DEFAULT_SETTINGS = [
'ephoto_dam',
'align',
'src',
'embed',
'width',
'height',
'alt',
'caption',
/**
* Default settings
*
* @const
*/
private const DEFAULT_SETTINGS = [
'ephoto_dam',
'align',
'src',
'embed',
'width',
'height',
'alt',
'caption',
];
/**
* ephoto_dam constructor.
*
* @param array $configuration Plugin configuration.
* @param string $plugin_id Plugin ID.
* @param mixed $plugin_definition Plugin definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function process($text, $langcode) {
$result = new FilterProcessResult($text);
foreach ($this->getValidMatches($text) as $source => $values) {
if($values['ephoto_dam'] === 'image') {
$html = $this->_renderImage((object) $values);
} else {
$html = $this->_renderEmbed((object) $values);
}
$text = str_replace($source, $html, $text);
$result->setAttachments(['library' => ['ephoto_dam/display']]);
//$response->setCacheContexts(['user.permissions']);
}
$result->setProcessedText($text);
return $result;
}
/**
* Render Image code html
*
* @param object $values Values of item
* @return string
*/
private function _renderImage($values) {
$html = '';
if($values->caption) {
$html .= '<figure class="caption caption-img ephoto-dam-align-' . $values->align . '" role="group">';
}
$html .= '<img';
$html .= ' alt="' . $values->alt . '"';
$html .= ' src="' . $values->src . '"';
$html .= ' width="' . $values->width . '"';
$html .= ' height="' . $values->height . '"';
$html .= ' class="' . ($values->zoom ? 'ephoto-dam-zoom' : '');
if(!$values->caption) $html .= ' align-' . $values->align;
$html .= '">';
if($values->caption) {
$html .= '<figcaption>' . $values->caption_data . '</figcaption>';
$html .= '</figure>';
}
return $html;
}
/**
* Render Embed code html
*
* @param object $values Values of item
* @return string
*/
private function _renderEmbed($values) {
$html = '';
if($values->caption) {
$html .= '<figure class="caption caption-img ephoto-dam-align-' . $values->align . '" role="group">';
}
$html .= '<iframe scrolling="no" allow="autoplay" allowfullscreen="true" frameborder="0"';
$html .= ' alt="' . $values->alt . '"';
$html .= ' src="' . $values->embed . '"';
$html .= ' width="' . $values->width . '"';
$html .= ' height="' . $values->height . '"';
if(!$values->caption) $html .= ' class="align-' . $values->align . '"';
$html .= '></iframe>';
if($values->caption) {
$html .= '<figcaption>' . $values->caption_data . '</figcaption>';
$html .= '</figure>';
}
return $html;
}
/**
* Get all valid matches in the WYSIWYG.
*
* @param string $text The text to check for WYSIWYG matches.
* @return array An array of data from the text keyed by the text content.
*/
protected function getValidMatches($text) {
// Use a look ahead to match the capture groups in any order.
if (!preg_match_all('/(<p>)?(?<json>{(?=.*ephoto_dam\b)(?=.*align\b)(?=.*src\b)(?=.*embed)(?=.*width)(?=.*height)(?=.*alt)(?=.*caption)(?=.*caption_data)(?=.*zoom)(.*)})(<\/p>)?/', $text, $matches)) {
return [];
}
$valid_matches = [];
foreach ($matches['json'] as $delta => $match) {
// Ensure the JSON string is valid.
$embed_data = json_decode($match, true);
if (!$embed_data || !is_array($embed_data)) {
continue;
}
if ($this->isValidSettings($embed_data)) {
$valid_matches[$matches[0][$delta]] = $embed_data;
}
}
return $valid_matches;
}
/**
* Check if the given settings are valid.
*
* @param array $settings Settings to validate.
* @return bool If the required settings are present.
*/
protected function isValidSettings($settings) {
foreach (self::DEFAULT_SETTINGS as $setting) {
if (!isset($settings[$setting])) {
return false;
}
}
return true;
}
/**
* ephoto_dam constructor.
*
* @param array $configuration Plugin configuration.
* @param string $plugin_id Plugin ID.
* @param mixed $plugin_definition Plugin definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public function process($text, $langcode) {
$result = new FilterProcessResult($text);
foreach ($this->getValidMatches($text) as $source => $values) {
if($values['ephoto_dam'] === 'image') {
$html = $this->_renderImage((object) $values);
} else {
$html = $this->_renderEmbed((object) $values);
}
$text = str_replace($source, $html, $text);
$result->setAttachments(['library' => ['ephoto_dam/display']]);
//$response->setCacheContexts(['user.permissions']);
}
$result->setProcessedText($text);
return $result;
}
/**
* Render Image code html
*
* @param object $values Values of item
* @return string
*/
private function _renderImage($values) {
$html = '';
if($values->caption) {
$html .= '<figure class="caption caption-img ephoto-dam-align-' . $values->align . '" role="group">';
}
$html .= '<img';
$html .= ' alt="' . $values->alt . '"';
$html .= ' src="' . $values->src . '"';
$html .= ' width="' . $values->width . '"';
$html .= ' height="' . $values->height . '"';
$html .= ' class="' . ($values->zoom ? 'ephoto-dam-zoom' : '');
if(!$values->caption) $html .= ' align-' . $values->align;
$html .= '">';
if($values->caption) {
$html .= '<figcaption>' . $values->caption_data . '</figcaption>';
$html .= '</figure>';
}
return $html;
}
/**
* Render Embed code html
*
* @param object $values Values of item
* @return string
*/
private function _renderEmbed($values) {
$html = '';
if($values->caption) {
$html .= '<figure class="caption caption-img ephoto-dam-align-' . $values->align . '" role="group">';
}
$html .= '<iframe scrolling="no" allow="autoplay" allowfullscreen="true" frameborder="0"';
$html .= ' alt="' . $values->alt . '"';
$html .= ' src="' . $values->embed . '"';
$html .= ' width="' . $values->width . '"';
$html .= ' height="' . $values->height . '"';
if(!$values->caption) $html .= ' class="align-' . $values->align . '"';
$html .= '></iframe>';
if($values->caption) {
$html .= '<figcaption>' . $values->caption_data . '</figcaption>';
$html .= '</figure>';
}
return $html;
}
/**
* Get all valid matches in the WYSIWYG.
*
* @param string $text The text to check for WYSIWYG matches.
* @return array An array of data from the text keyed by the text content.
*/
protected function getValidMatches($text) {
// Use a look ahead to match the capture groups in any order.
if (!preg_match_all('/(<p>)?(?<json>{(?=.*ephoto_dam\b)(?=.*align\b)(?=.*src\b)(?=.*embed)(?=.*width)(?=.*height)(?=.*alt)(?=.*caption)(?=.*caption_data)(?=.*zoom)(.*)})(<\/p>)?/', $text, $matches)) {
return [];
}
$valid_matches = [];
foreach ($matches['json'] as $delta => $match) {
// Ensure the JSON string is valid.
$embed_data = json_decode($match, true);
if (!$embed_data || !is_array($embed_data)) {
continue;
}
if ($this->isValidSettings($embed_data)) {
$valid_matches[$matches[0][$delta]] = $embed_data;
}
}
return $valid_matches;
}
/**
* Check if the given settings are valid.
*
* @param array $settings Settings to validate.
* @return bool If the required settings are present.
*/
protected function isValidSettings($settings) {
foreach (self::DEFAULT_SETTINGS as $setting) {
if (!isset($settings[$setting])) {
return false;
}
}
return 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