🇵🇱Poland @pawel.traczynski

Warsaw
Account created on 23 August 2008, over 16 years ago
#

Recent comments

🇵🇱Poland pawel.traczynski Warsaw

#25 worked for me. Probably would be great to limit shown options until any content bundle is selected in filter config? Or something else that would prevent loading all nodes while editing the filter?

🇵🇱Poland pawel.traczynski Warsaw

I have tried many ways to successfully send an email using mime mail but ended up commenting out the line code in MimeMailFormatHelper class:

  if (!isset($headers['Return-Path']) || $headers['Return-Path'] == $default_from) {
    // $headers['Return-Path'] = '<' . static::mimeMailAddress($from, TRUE) . '>';
    // @see https://www.drupal.org/files/issues/2024-11-20/3488497-1-fix-error-email-not-comply-RFC-2822.patch
    // @see https://www.drupal.org/project/mimemail/issues/3257799
      }

With this everything works, except another hack that I had to implement in the same file, which allowed MimeMail to properly send out emails with Date heade set.

// Run all string headers through UnstructuredHeader() to convert non-ASCII
// characters to an RFC compliant string.
foreach ($headers as $field_name => $field_body) {
  // Drupal uses Symfony\Component\Mime\Header\Headers class, where not
  // all headers are expected/required to be strings (e.g. 'Date' header
  // is required to be DateTime object). Because of it, skip processing
  // header body if it is not string.
  if (!is_string($field_body)) {
    continue;
  }

  $headers[$field_name] = (new UnstructuredHeader($field_name, $field_body))->getBodyAsString();
}

https://www.drupal.org/project/mimemail/issues/3408278#comment-15358107 🐛 Mimemail runs all http headers through UnstructuredHeader() while it should not Active

I am providing this info here because the issue affects the same file. Maybe it helps someone.

🇵🇱Poland pawel.traczynski Warsaw

Hi. The method from #10 is adding a link to the mail.css in the mimemail-message template. From what I saw it did not work in all cases. To actually add the CSS into the template, I have used the below code:

/** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
  $theme_handler = \Drupal::service('theme_handler');
  $theme_path = $theme_handler->getTheme('YOUR_THEME')->getPath();

  $css = FALSE;
  // Assuming mail.css is in a /css subdirectory where all other css is.
  $css_path = DRUPAL_ROOT . '/' . $theme_path . '/css/mail.css';

  try {
    $css = file_get_contents($css_path);
  }
  catch (Exception $exception) {
    Drupal::logger('YOUR_THEME')->error(t('Failed to get contentns of mail.css file while using mimemail-message template. Exception message: @exception', [
      '@exception' => $exception->getMessage(),
    ]));
  }

  if ($css) {
    $variables['css'] = $css;
  }

With this code there is not need to modify the mimemail-message twig template unless you want to add some additional markup in it.

I hope this helps someone.

🇵🇱Poland pawel.traczynski Warsaw

Thanks @joelpittet. I found the first reply starting with "Well, no" to not be good start of a constructive conversation either but I see the point. I have provided patch and solution. Has it been integrated into the module?

🇵🇱Poland pawel.traczynski Warsaw

How can I help further, despite the patch provided, to have this fixed? If you don't have time then add me as a maintainer and I will fix it.

🇵🇱Poland pawel.traczynski Warsaw

Thanks. I have uploaded screenshot there.

🇵🇱Poland pawel.traczynski Warsaw

What @ wrd-oaitsd is saying is that you cannot add class attribute like so:

<ol class> <ul class> <a class>

under Source editing when you have Ckeditor Style button placed active.

I confirm this is a problem in Drupal 10. Currently digging for a solution.

🇵🇱Poland pawel.traczynski Warsaw

The Drupal core caption filter did not work for me either for the resons mentioned above.

Here is how I achived captions for embedded media images while being in full control of the HTML markup.

I needed to give the user an option to:
- embed image while being able to pick image style: I have created one style for tall/portrait image and one for wide/full content width image
- allow them to provide caption
- use my own markup for the image printed image style and the caption

1. I have setup media bundle 'image' and added 'media_caption' formatted text field in it. The caption format allowed paragraphs and links to that instead of plain text captions, a caption could be multiple paragraphs or could contain a link. For this purpose I have used a text format that I already had on my site that allows exactly and only this.

2. Then configured two different view modes for media, where each view mode used different image style for the image. One view mode machine name was 'image_full' and the other was 'image_tall'.

3. The custom templates for embedded image media I needed to be global, that is I neeeded them to be picked up independently of theme being in use. For this reason I have registered my own media templates in my module:

/**
 * Implements hook_theme().
 */
function MODULE_theme($existing, $type, $theme, $path) {
  return [
    // Use custom templates for 'media' with 'image' bundle and
    // with 'image-...' view modes.
    'media__image__image_full' => [
      'template' => 'media-image',
      'render element' => 'elements',
      'base hook' => 'media',
    ],
    'media__image__image_tall' => [
      'template' => 'media-image',
      'render element' => 'elements',
      'base hook' => 'media',
    ],
  ];
}

As you can see I used single template for both view modes. Because of using my templates only for my view modes, other view modes, like those used in the Media administration page are not impacted and will continue to display normally without breaking the admin UI styling.

4. The custom media-image.html.twig template looked like this:

<figure{{ attributes }}>
  {{ title_suffix.contextual_links }}
  {{ content|without('media_caption') }}

  {% if media_caption %}
    <figcaption class="fix-margins">{{ media_caption }}</figcaption>
  {% endif %}
</figure>

5. Then to support my own template and my markup requirements I added this template preprocess:

/**
 * Preprocess variables for media template.
 *
 * Providing custom classes and values to media-image templates.
 */
function MODULE_preprocess_media(&$variables) {
  /** @var \Drupal\media\MediaInterface $media */
  $media = $variables['elements']['#media'];

  /** @var \Drupal\MODULE\Common $common */
  $common = \Drupal::service('MODULE.common');

  $bundle = $media->bundle();
  $view_mode = $variables['elements']['#view_mode'];

  if ($bundle == 'image' && in_array($view_mode, ['image_full', 'image_tall'])) {
    // Converts view mode like 'image_full' to 'full'.
    $image_mode = str_replace('image_', '', $view_mode);

    $variables['attributes']['class'][] = 'img';
    $variables['attributes']['class'][] = 'img-' . $image_mode;

    // This just assigns caption value from media entity to a variable.
    // If value is missing this will equal FALSE.
    $variables['media_caption'] = $common->fieldValue('media_caption', $media, FALSE);
  }
}

Thats it. Now when Embed Media button it pressed, when user uploads a new image, they will see a custom caption field. In addition when the insert the image into CKEditor5, they will see a dropdown to pick the image style to use.

I have implemented this as an "Insert" module replacement for CK5.

So far the only downsides of this solution are:
- once the image has been inserted into ckeditor5 content, then if user wants to edit the caption again, they have to edit it in the media, for example by editing the media on the media administration page
- the caption is global for a single media item. You cannot insert the media in different nodes while having different captions for each.

🇵🇱Poland pawel.traczynski Warsaw

Unfortunately you are wrong.

I suggest you test it without the mimemail module enabled, so just using Drupal Core PHP Mailer:

1. Send email with 'Date' email header set to DateTimeInterface $message['headers']['Date'] = new DateTime();. The email will send correctly.

2. Now send another email but this set 'Date header to any string date, like a result of date('r') $message['headers']['Date'] = date('r'); You will get this error:

TypeError: Symfony\Component\Mime\Header\Headers::addDateHeader(): Argument #2 ($dateTime) must be of type DateTimeInterface, string given, called in \vendor\symfony\mime\Header\Headers.php on line 152 in Symfony\Component\Mime\Header\Headers->addDateHeader() (line 114 of \vendor\symfony\mime\Header\Headers.php).

Symfony\Component\Mime\Header\Headers->addHeader('Date', 'Wed, 13 Dec 2023 08:29:21 +0100') (Line: 102)
Drupal\Core\Mail\Plugin\Mail\PhpMail->mail(Array) (Line: 50)
Drupal\mailsystem\Adapter->mail(Array) (Line: 307)
Drupal\Core\Mail\MailManager->doMail('mymodule', 'mykey', 'user@example.com', 'pl', Array, NULL, 1) (Line: 180)
Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}() (Line: 592)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 181)
Drupal\Core\Mail\MailManager->mail('mymodule', 'mykey', 'user@example.com', 'pl', Array, NULL, 1) (Line: 70)

As you can see a DateTimeInterface object is expected, NOT a string.

🇵🇱Poland pawel.traczynski Warsaw

Added explanations of how to handle block cache.

🇵🇱Poland pawel.traczynski Warsaw

For anyone looking for a fix, exporting the view to config/sync as yml, removing the cache_metadata.contexts.user and importing the config back to site fixed the caching issue for me.

🇵🇱Poland pawel.traczynski Warsaw

I ended up removing field and adding another one, since I did not care about keeping configured 'Focus keyword' values in my case.

🇵🇱Poland pawel.traczynski Warsaw

I also have the same issue after updating 1.7 to 1.8.

🇵🇱Poland pawel.traczynski Warsaw

This is exactly the same issue with grouped date filters as it was in D7 back then:
https://www.drupal.org/project/views/issues/3123292

In the linked thread there is my fix for D7. If I develop fix for D9/10 I will post it here.

🇵🇱Poland pawel.traczynski Warsaw

Damien - with the latest version of Date 2.14, the problem still persists.
Commenting out this line:

$form['value']['#id'] = 'date_views_exposed_filter-' . bin2hex(drupal_random_bytes(16));

fixes the problem. I understand it might cause problem elsewhere but I did not

🇵🇱Poland pawel.traczynski Warsaw

For me this works:

  if ($conf['auto_lang'] == "f") {
    $settings['language'] = $conf['lang'];
    //
            
              #1473010: [D7] Spell checker set to use interface language
            
    $settings['scayt_sLang'] = ckeditor_scayt_langcode($conf['lang']);
  }
  ### PATCH START ###
  else {
    $settings['language'] = $language->language;
  }
  ### PATCH END ###

file: ckeditor/includes/ckeditor.lib.inc

🇵🇱Poland pawel.traczynski Warsaw

The jquery_ui module now hosts the entire jQuery UI library, and that the jquery_ui_datepicker module only forces inclusion of jquery_ui module in a version 1.6 which ships with the jquery ui datepicker. Beside this the version 2.0.0 of the module doesn't do anything else on it's own.

On the other hand the jquery_ui module uses hook_library_info_alter() where it looks at what are enabled jquery ui submodules, and if specific submodule is found, then the jquery UI function is added.

My understanding is that this is for compatibility and for other contribs to be able to add depdendencies for specific functions of the jquery ui. Anways my preference would be to rather enable jquery ui functions using checkboxes in the backend.

Production build 0.71.5 2024