Account created on 5 November 2009, about 15 years ago
#

Recent comments

🇬🇷Greece dotoree

Update issue's version to 2.1.6 as it's not only present on ^2.1@alpha.

🇬🇷Greece dotoree

Yet again, the problem still exists with gin 3.0.0-rc15 and mercury_editor 2.1.6 .

If it helps anybody, I came up with a hack in a custom module to prevent nodes to be unpublished. I assume that the site has a node bundle 'mercury_enabled_page' that uses mercury.

use Drupal\node\NodeInterface;

/**
 * Implements hook_entity_presave().
 *
 * Temporarily hack for issue https://www.drupal.org/project/mercury_editor/issues/3406870.
 */
function my_module_entity_presave(\Drupal\Core\Entity\EntityInterface $entity) {
  // Check if the entity is a node and of the bundle 'mercury_enabled_page'.
  if ($entity instanceof NodeInterface && $entity->bundle() === 'mercury_enabled_page') {
    // Get the referrer URL from the global request.
    $referrer = \Drupal::request()->server->get('HTTP_REFERER');
    // Check if the referrer URL contains 'mercury-editor'.
    if (strpos($referrer, 'mercury-editor') !== FALSE) {
      // Set the node status to TRUE (published).
      $entity->set('status', TRUE);
    }
  }
}
🇬🇷Greece dotoree

I managed to solve it like this:

Creating a my_module.ckeditor5.yml (like #4):

# my_module/my_module.ckeditor5.yml
media_lite_youtube_embed:
  provider: media
  ckeditor5:
    plugins:
      - drupalMedia.DrupalMedia
  drupal:
    label: lite_youtube_embed
    library: lite_youtube_embed/lite_youtube_embed
    elements:
      - <lite-youtube>
      - <lite-youtube videoid playlabel params>
    conditions:
      filter: media_embed

add library and css in my_module:

// my_module/css/lite_youtube_embed.css
figure.drupal-media.ck-widget:has(lite-youtube) {
  display: block;
  float: none;
}
figure.drupal-media.ck-widget lite-youtube {
  min-height: var(--ck-min-height);
  aspect-ratio: 16 / 10;
}

then add a preprocess hook in my_module:

// my_module/my_module.module
/**
 * Implements hook_preprocess_page().
 */
function my_module_preprocess_page(&$variables) {
  // Embed does not render in CKEditor 5
  if (\Drupal::service('router.admin_context')->isAdminRoute()) {
    $variables['#attached']['library'][] = 'my_module/lite_youtube_embed';
  }
}
🇬🇷Greece dotoree

The problem still exists with gin 3.0.0-rc14 and mercury_editor 2.1.3, dev versions as well. I can't tell if it's Gin or ME problem.

🇬🇷Greece dotoree

@boinkster: One potential caveat is that your custom module (aka 'my_module' in example) should fire after mercury editor. This can be done with some something like Modules Weight module or with custom code.

🇬🇷Greece dotoree

The problem is that status field belongs to gin_actions group and form renders without this group, so we need to move status out of this group.

Not sure in which level should be patched, but you can override the template through a custom module to fix the problem:

a) create a new module 'my_module' and make sure that executes after mercury_editor

b) create a template in my_module/templates named 'mercury-editor-entity-form--custom.html.twig' with contents:

{#
/**
 * @file
 * Theme override for a node edit form.
 *
 * Single-column template for the node edit form.
 *
 * @see claro_form_node_form_alter()
 */
#}
{{ attach_library('mercury_editor/node_form') }}
{{ form['status_messages'] }}
<header class="me-node-form__header">
  <h1 class="me-node-form__title">{{ form['#title'] }}</h1>
</header>
{# Remove status group when in gin_actions #}
{% if form.status['#group'] == 'gin_actions' %}
  {% set status = form.status %}
  {% set status = status|merge({ '#group' : null }) %}
  {% set form = form|merge({ status: status }) %}
{% endif %}
{{ form|without('status_messages', 'advanced', 'footer', 'actions', 'gin_actions', 'gin_sidebar', 'gin_sidebar_toggle') }}
{{ form.advanced }}
{{ form.actions }}
{{ form.footer }}

c) in my_module.module:

/**
 * Implements hook_theme_suggestions_alter().
 */
function my_module_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
  switch ($hook) {
    case 'node_edit_form':
      if (in_array('mercury_editor_entity_form', $suggestions)) {
        $suggestions[] = 'mercury_editor_entity_form__custom';
      }
      break;
  }
}

/**
 * Implements hook_theme().
 */
function my_module_theme($existing, $type, $theme, $path) {
  return [
    'mercury_editor_entity_form__custom' => [
      'base hook' => 'mercury_editor_entity_form',
    ],
  ];
}
Production build 0.71.5 2024