Skip to content
Snippets Groups Projects
Commit 41e1d67a authored by Andy Marquis's avatar Andy Marquis
Browse files

Issue #3440894 by apmsooner: Coding standards

parent 226673ad
No related branches found
No related tags found
1 merge request!73440894: Code cleanup.
Pipeline #147256 passed with warnings
......@@ -40,14 +40,14 @@
}
#drupal-off-canvas .visual-editor-breadcrumbs li {
display:inline;
display: inline;
list-style: none;
font-size: small;
}
#drupal-off-canvas-wrapper .js-media-library-item.media-library-item.media-library-item--grid {
max-width: 100% !important;
width: auto !important;
max-width: 100% !important;
}
#drupal-off-canvas-wrapper .form-element {
......@@ -59,4 +59,3 @@
width: 85% !important;
max-width: 85% !important;
}
......@@ -3,7 +3,7 @@
* Site preview.
*/
(function($, window, Drupal, drupalSettings) {
(function ($, window, Drupal, once, drupalSettings) {
$.fn.drupalAjax = (url) => {
const ajaxSettings = {
url,
......@@ -14,73 +14,88 @@
};
Drupal.ajax(ajaxSettings).execute();
return;
}
};
$.fn.visualEditorReload = (storage, id) => {
if (storage === 'node' && id) {
// Reload node after save to refresh form state.
// The content has either been modified by another user,
// or you have already submitted modifications.
// The content has either been modified by another user,
// or you have already submitted modifications.
// As a result, your changes cannot be saved.
const path = `/node/${id}`
// Reload Drupal page to refresh form state.
window.location.href = path
// Use once error message is fixed.
// $iframe[0].src = src;
// $.fn.drupalAjxax(`/visual_editor/form/node/${node}/edit?preview=${false}`);
window.location.href = `/node/${id}`;
}
return;
}
};
Drupal.behaviors.visualEditorLoad = {
attach(context) {
const { open_load, is_preview = false, is_revision = false } = drupalSettings.visual_editor.node_view;
const { selector, node } = drupalSettings.decoupled_preview_iframe.node_view;
once('visual_editor', selector, context).forEach(function () {
if (!is_revision && open_load && node) {
$.fn.drupalAjax(`/visual_editor/form/node/${node}/edit?preview=${is_preview}`);
const {
openLoad,
isPreview = false,
isRevision = false,
} = drupalSettings.visual_editor.node_view;
const { selector, node } =
drupalSettings.decoupled_preview_iframe.node_view;
once('visual_editor', selector, context).forEach(() => {
if (!isRevision && openLoad && node) {
$.fn.drupalAjax(
`/visual_editor/form/node/${node}/edit?preview=${isPreview}`,
);
}
});
}
},
};
Drupal.behaviors.visualEditorListener = {
attach() {
window.addEventListener("message", (event) => {
const { wrapper } = drupalSettings.visual_editor.node_view;
const { data } = event
if (data.type === 'VISUAL_EDITOR_COMPONENT') {
const { uuid } = data;
const inputId = jQuery(`input[data-visual-editor-uuid="${uuid}"]`).attr('id');
const divSelector = 'edit-'+inputId.substring(0, inputId.indexOf("-edit--"));
const divId = jQuery(`div[data-drupal-selector="${divSelector}"]`).attr('id');
window.addEventListener(
'message',
(event) => {
const { wrapper } = drupalSettings.visual_editor.node_view;
const { data } = event;
if (data.type === 'VISUAL_EDITOR_COMPONENT') {
const { uuid } = data;
const uuidInput = $(`input[data-visual-editor-uuid="${uuid}"]`);
const inputId = uuidInput.attr('id');
const divSelector = `edit-${inputId.substring(
0,
inputId.indexOf('-edit--'),
)}`;
const divId = $(`div[data-drupal-selector="${divSelector}"]`).attr(
'id',
);
if (wrapper.type && wrapper.mode && wrapper.selector && wrapper.position) {
if (wrapper.type === 'tab' && Number(wrapper.position) > 0) {
const wrapperSelector = `${wrapper.selector} > .${wrapper.mode}-${wrapper.type}s > .${wrapper.mode}-${wrapper.type}s-list > .${wrapper.mode}-${wrapper.type}-button-${Number(wrapper.position)-1}`;
jQuery(wrapperSelector).children(0).click();
if (
wrapper.type &&
wrapper.mode &&
wrapper.selector &&
wrapper.position
) {
if (wrapper.type === 'tab' && Number(wrapper.position) > 0) {
const wrapperSelector = `${wrapper.selector} > .${
wrapper.mode
}-${wrapper.type}s > .${wrapper.mode}-${
wrapper.type
}s-list > .${wrapper.mode}-${wrapper.type}-button-${
Number(wrapper.position) - 1
}`;
$(wrapperSelector).children(0).click();
}
}
}
// Expand paragraph
jQuery(`input[data-visual-editor-uuid="${uuid}"]`).trigger("mousedown");
// Scroll to paragraph
document.getElementById(divId).scrollIntoView({
behavior: 'smooth',
block: 'start',
inline: 'end'
});
event.stopImmediatePropagation();
return;
}
}, false);
}
}
})(jQuery, window, Drupal, drupalSettings);
// Expand paragraph
uuidInput.trigger('mousedown');
// Scroll to paragraph
document.getElementById(divId).scrollIntoView({
behavior: 'smooth',
block: 'start',
inline: 'end',
});
event.stopImmediatePropagation();
}
},
false,
);
},
};
})(jQuery, window, Drupal, once, drupalSettings);
......@@ -2,11 +2,11 @@
/**
* @file
* Install, update and uninstall functions for the Visual Editor Paragraphs module.
* Install, update and uninstall functions for the Visual Editor Paragraphs.
*/
/**
* {@inheritDoc}
* Implements hook_install().
*/
function visual_editor_paragraphs_install() {
module_set_weight('visual_editor_paragraphs', 10);
......
......@@ -5,10 +5,6 @@
* Implements hooks for the Visual Editor Paragraphs module.
*/
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\InvokeCommand;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_paragraphs_widget_actions_alter().
*/
......
......@@ -3,7 +3,6 @@
namespace Drupal\visual_editor\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityRepository;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -12,19 +11,20 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityForm extends ControllerBase {
/**
* Construct a new Visual Editor Node-Edit Controller.
* The entity repository service.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
public function __construct(
protected EntityRepository $entityRepository,
) {}
protected $entityRepository;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.repository'),
);
$instance = parent::create($container);
$instance->entityRepository = $container->get('entity.repository');
return $instance;
}
/**
......
......@@ -4,21 +4,12 @@ declare(strict_types=1);
namespace Drupal\visual_editor\Form;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Ajax\AjaxFormHelperTrait;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\InvokeCommand;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\node\NodeForm;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\visual_editor\FormEditTrait;
/**
......@@ -28,58 +19,6 @@ class NodeEditForm extends NodeForm {
use FormEditTrait;
use AjaxFormHelperTrait;
/**
* Constructs a NodeForm object.
*
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $temp_store_factory
* The factory for the temp store object.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
* Drupal entity field manager.
*/
public function __construct(
EntityRepositoryInterface $entity_repository,
PrivateTempStoreFactory $temp_store_factory,
EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL,
TimeInterface $time = NULL,
AccountInterface $current_user,
DateFormatterInterface $date_formatter,
protected EntityFieldManagerInterface $entityFieldManager,
) {
parent::__construct(
$entity_repository,
$temp_store_factory,
$entity_type_bundle_info,
$time,
$current_user,
$date_formatter,
);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.repository'),
$container->get('tempstore.private'),
$container->get('entity_type.bundle.info'),
$container->get('datetime.time'),
$container->get('current_user'),
$container->get('date.formatter'),
$container->get('entity_field.manager'),
);
}
/**
* {@inheritdoc}
*
......
......@@ -4,8 +4,10 @@ declare(strict_types=1);
namespace Drupal\visual_editor\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -15,26 +17,55 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class SettingsForm extends ConfigFormBase {
/**
* The entity type bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* The entity field manager.
*
* @var \Drupal\Core\Entity\EntityFieldManagerInterface
*/
protected $entityFieldManager;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Construct a new Settings form.
*
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entityTypeBundleInfo
* Drupal entity type bundle service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager
* Drupal entity field manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* Defines the configuration object factory.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The Drupal entity type bundle service.
* @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
* The Drupal entity field manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* Manage drupal modules.
*/
public function __construct(
protected EntityTypeBundleInfoInterface $entityTypeBundleInfo,
protected EntityFieldManagerInterface $entityFieldManager,
) {}
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeBundleInfoInterface $entity_type_bundle_info, EntityFieldManagerInterface $entity_field_manager, ModuleHandlerInterface $module_handler) {
parent::__construct($config_factory);
$this->entityTypeBundleInfo = $entity_type_bundle_info;
$this->entityFieldManager = $entity_field_manager;
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('entity_type.bundle.info'),
$container->get('entity_field.manager'),
$container->get('module_handler'),
);
}
......@@ -62,13 +93,6 @@ class SettingsForm extends ConfigFormBase {
'#name' => 'basic',
];
// $form['basic']['framework'] = [
// '#type' => 'textfield',
// '#title' => $this->t('Framework module name'),
// '#default_value' => $this->config('visual_editor.settings')->get('framework'),
// '#group' => 'basic',
// ];
$form['basic']['disable_styles'] = [
'#type' => 'checkbox',
'#title' => 'Disable default Off-Canvas Styles',
......@@ -83,7 +107,7 @@ class SettingsForm extends ConfigFormBase {
'#group' => 'basic',
];
$isFieldGroup = \Drupal::moduleHandler()->moduleExists('field_group');
$isFieldGroup = $this->moduleHandler->moduleExists('field_group');
$form['wrapper'] = [
'#type' => 'details',
......
......@@ -4,12 +4,25 @@ declare(strict_types=1);
namespace Drupal\visual_editor;
/**
* Trait for \Drupal\visual_editor\Form\NodeEditForm.
*/
trait FormEditTrait {
/**
* Sets the entity for sidebar edit form.
*
* @param array $form
* The form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*
* @return \Drupal\Core\Entity\ContentEntityInterface
* The node object to return.
*/
public function calculateNodeEntity(&$form, &$form_state) {
$is_preview = \Drupal::request()->query->has('preview') ?
(\Drupal::request()->query->get('preview') == 'true') :
FALSE;
$query = \Drupal::request()->query;
$is_preview = $query->has('preview') && $query->get('preview') == 'true';
// Try to restore from temp store, this must be done before calling
// parent::form().
......@@ -35,7 +48,8 @@ trait FormEditTrait {
$form_state->set('has_been_previewed', TRUE);
return $this->entity;
} else {
}
else {
$this->entity = $form_state->getFormObject()->getEntity();
return $form_state->getFormObject()->getEntity();
}
......
......@@ -6,7 +6,7 @@
*/
/**
* {@inheritDoc}
* Implements hook_install().
*/
function visual_editor_install() {
module_set_weight('visual_editor', 10);
......
......@@ -5,12 +5,12 @@
* Implements hooks for the remix module.
*/
use Drupal\visual_editor\Form\NodeEditForm;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\CloseDialogCommand;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\visual_editor\Form\NodeEditForm;
/**
* Implements hook_theme().
......@@ -87,15 +87,15 @@ function visual_editor_node_view_alter(array &$build, EntityInterface $entity, E
$build['iframe']['#attached']['library'][] = 'visual_editor/node_view';
$build['iframe']['#attached']['drupalSettings']['visual_editor'] = [
'node_view' => [
'open_load' => $open_load,
'is_preview' => $node_preview != NULL,
'is_revision' => $routeName === 'entity.node.revision',
'openLoad' => $open_load,
'isPreview' => $node_preview != NULL,
'isRevision' => $routeName === 'entity.node.revision',
'wrapper' => [
'type' => $config->get('wrapper.type'),
'mode' => $config->get('wrapper.mode'),
'selector' => $config->get('wrapper.selector'),
'position' => $config->get('wrapper.position'),
]
],
],
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment