Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use patterns defined in oe_theme when admin theme is active #204

Open
vever001 opened this issue Apr 17, 2019 · 1 comment
Open

Can't use patterns defined in oe_theme when admin theme is active #204

vever001 opened this issue Apr 17, 2019 · 1 comment

Comments

@vever001
Copy link

Hello,

I setup entity_embed on my website to embed media entities (documents for now).
I noticed that nothing gets displayed when we are in edit mode (admin theme active - seven) and attempt to display a media entity that uses a pattern defined in oe_theme (the file pattern here).

I haven't seen any entity_embed integration in OE modules so far. Perhaps you plan to do it later?
One solution would be to move all UI Patterns oe_theme_helper I guess ?

Anyway here is a workaround I used to format the embedded view mode of documents:

/**
 * Preprocessor for Media Document embedded.
 */
function mymodule_preprocess_media__document__embedded(array &$variables) {
  // @TODO The "file" pattern currently defined in oe_theme is not found when
  // we are in edit mode with the admin theme active.
  // So we abort when we're on the admin theme
  // But this needs to be fixed somehow...
  $admin_theme = \Drupal::config('system.theme')->get('admin');
  $current_theme = \Drupal::theme()->getActiveTheme()->getName();
  if ($admin_theme === $current_theme) {
    return;
  }

  /** @var \Drupal\media\Entity\Media $media_entity */
  $media_entity = $variables['media'];
  $media_source = $media_entity->getSource();
  $source_field_name = $media_source->getConfiguration()['source_field'];
  /** @var \Drupal\file\Entity\File $file_entity */
  $file_entity = $media_entity->get($source_field_name)->entity;

  $file_value_object = FileValueObject::fromFileEntity($file_entity);
  $file_value_object->setTitle($media_entity->getName());
  $variables['content'] = [
    '#type' => 'pattern',
    '#id' => 'file',
    '#variant' => '',
    '#fields' => [
      'button_label' => t('Download'),
      'file' => $file_value_object,
    ],
  ];
}

Any advice on this is welcome.

@vever001
Copy link
Author

vever001 commented Aug 3, 2020

Most probably linked to nuvoleweb/ui_patterns#298

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant