Skip to content
This repository has been archived by the owner on Nov 16, 2021. It is now read-only.

Commit

Permalink
Issue #2784699 by phenaproxima: Provide option for resizing inline im…
Browse files Browse the repository at this point in the history
…ages
  • Loading branch information
phenaproxima authored and balsama committed Jun 29, 2017
1 parent d0effa3 commit 7b1456b
Show file tree
Hide file tree
Showing 38 changed files with 647 additions and 110 deletions.
26 changes: 26 additions & 0 deletions UPDATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,32 @@ use. For example, if you are currently running Beta 1 and are trying to update
to Beta 3, you will need to follow the instructions for updating from Beta 1 to
Beta 2, then from Beta 2 to Beta 3, in that order.

## 2.1.5 to 2.1.6
This version of Lightning adds the ability to choose an image style, alt text,
and other settings each time you embed an image in a WYSIWYG editor, rather
that needing to rely on view modes. To enable this functionality:

1. As always, visit ```update.php``` or run ```drush updatedb``` to perform
database updates.
1. Clear all caches.
1. Under *Configuration > Content Authoring > Text formats and editors*,
configure the **Rich Text** filter format. Under "Filter settings", open the
tab labeled "Limit allowed HTML tags and correct faulty HTML".
1. In the "Allowed HTML tags" text field, you should see a tag like
`<drupal-entity data-*>`. Change it to `<drupal-entity data-* alt title>`.
1. Save the filter format.
1. Under *Configuration > Content Authoring > Text editor embed buttons*, edit
the "Media browser" embed button.
1. Under "Allowed Entity Embed Display plugins", ensure that the "Media Image"
checkbox is checked.
1. Save the embed button.
1. If you would like to allow authors to choose how embedded media should be
displayed, go to *Configuration > System > Lightning > Media*, ensure that
the box labeled "Allow users to choose how to display embedded media" is
checked, then submit the form. If the box is not checked, Lightning will
automatically choose a preferred display method (the recommended, default
behavior).

## 2.1.4 to 2.1.5
There are no manual update steps for this version.

Expand Down
6 changes: 4 additions & 2 deletions lightning.install
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\lightning_core\ConfigHelper as Config;
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;

Expand Down Expand Up @@ -457,7 +458,8 @@ function lightning_update_8001() {
// Install the body field on the basic block_content type.
$field = FieldConfig::load('block_content.basic.body');
if (empty($field)) {
lightning_core_create_config('field_config', 'block_content.basic.body', 'lightning');
$config = Config::forModule('lightning');
$config->getEntity('field_config', 'block_content.basic.body')->save();

$display = EntityViewDisplay::load('block_content.basic.default');
if ($display) {
Expand All @@ -471,7 +473,7 @@ function lightning_update_8001() {
])->save();
}
else {
lightning_core_create_config('entity_view_display', 'block_content.basic.default', 'lightning');
$config->getEntity('entity_view_display', 'block_content.basic.default')->save();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
* Contains installation and update routines for Lightning Dev.
*/

use Drupal\embed\Entity\EmbedButton;
use Drupal\entity_browser\Entity\EntityBrowser;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\filter\Entity\FilterFormat;
use Drupal\lightning_core\ConfigHelper as Config;
use Drupal\media_entity\Entity\MediaBundle;
use Drupal\scheduled_updates\Entity\ScheduledUpdateType;
Expand Down Expand Up @@ -192,3 +194,20 @@ function lightning_dev_update_8005() {
$display['display_options']['filters']['bundle']['expose']['argument'] = 'bundle';
$view->save();
}

/**
* Executes manual updates for Lightning 2.1.5 --> 2.1.6.
*/
function lightning_dev_update_8006() {
\Drupal::service('plugin.manager.embed.type')->clearCachedDefinitions();

$button = EmbedButton::load('media_browser');
$settings = $button->getTypeSettings();
$settings['display_plugins'][] = 'media_image';
$button->set('type_settings', $settings)->save();

$format = FilterFormat::load('rich_text');
$configuration = $format->filters('filter_html')->getConfiguration();
$configuration['settings']['allowed_html'] = str_replace('<drupal-entity data-*>', '<drupal-entity data-* title alt>', $configuration['settings']['allowed_html']);
$format->setFilterConfig('filter_html', $configuration)->save();
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,6 @@ function lightning_test_install() {
],
'region' => 'content',
])
->setComponent('field_z_image', [
'type' => 'entity_browser_entity_reference',
'settings' => [
'entity_browser' => 'media_browser',
'field_widget_display' => 'rendered_entity',
'field_widget_edit' => TRUE,
'field_widget_remove' => TRUE,
'selection_mode' => EntityBrowserElement::SELECTION_MODE_APPEND,
'field_widget_display_settings' => [
'view_mode' => 'embedded',
],
'open' => TRUE,
],
'region' => 'content',
])
->save();

$display = entity_get_form_display('media', 'video', 'default');
Expand Down Expand Up @@ -144,9 +129,4 @@ function lightning_test_uninstall() {
}
}
$state->delete('_fields');

\Drupal::entityTypeManager()
->getStorage('media_bundle')
->load('z_image')
->delete();
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function delete($id) {
if (Unicode::strpos($id, $prefix) === 0) {
$entity = $this->getEntity(
$entity_type,
Unicode::substr($id, Unicode::strlen($prefix) + 1)
Unicode::substr($id, Unicode::strlen($prefix))
);
return $entity->delete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type_settings:
bundles: { }
display_plugins:
- 'entity_reference:entity_reference_entity_view'
- media_image
entity_browser: media_browser
entity_browser_settings:
display_review: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ dependencies:
module:
- editor
- entity_embed
_core:
default_config_hash: ba3RWDN1-BRYH1z2GlIchbXVWirdh7mDbsjSmbCmbIw
name: 'Rich Text'
format: rich_text
weight: 1
Expand Down Expand Up @@ -46,7 +44,7 @@ filters:
status: true
weight: -50
settings:
allowed_html: '<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <s> <sup> <sub> <img src alt data-entity-type data-entity-uuid data-align data-caption> <table> <caption> <tbody> <thead> <tfoot> <th> <td> <tr> <hr> <p> <br> <h1> <pre> <drupal-entity data-*>'
allowed_html: '<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <s> <sup> <sub> <img src alt data-entity-type data-entity-uuid data-align data-caption> <table> <caption> <tbody> <thead> <tfoot> <th> <td> <tr> <hr> <p> <br> <h1> <pre> <drupal-entity data-* title alt>'
filter_html_help: true
filter_html_nofollow: false
filter_autop:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
entity_embed:
choose_display: false
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
lightning_media.settings:
type: config_object
label: 'Lightning Media settings'
mapping:
entity_embed:
type: mapping
label: 'Entity Embed settings'
mapping:
choose_display:
type: boolean
label: 'Allow user to choose display plugin for embedded media'

entity_browser.browser.widget.embed_code:
type: mapping
label: 'Embed code widget settings'
Expand Down
16 changes: 13 additions & 3 deletions modules/lightning_features/lightning_media/lightning_media.install
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,25 @@ function lightning_media_update_8015() {
->save();
}

/**
* Creates the lightning_media.settings config object.
*/
function lightning_media_update_8016() {
Config::forModule('lightning_media')
->get('lightning_media.settings')
// The default value of this setting changes the behavior of the Entity
// Embed dialog. Rather than break an existing workflow, change the new
// configuration to preserve the old behavior.
->set('entity_embed.choose_display', TRUE)
->save();
}

/**
* Implements hook_update_dependencies().
*/
function lightning_media_update_dependencies() {
return [
'lightning_media' => [
8004 => [
'lightning' => 8002,
],
// 8012 adds the field_media_in_library filter to the Entity Browser
// display of the media view, which is created by 8008.
8012 => [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lightning_media.settings:
route_name: lightning_media.settings
title: 'Media'
base_route: lightning_core.settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
lightning_media.settings:
path: '/admin/config/system/lightning/media'
defaults:
_title: Lightning
_form: '\Drupal\lightning_media\Form\SettingsForm'
requirements:
_is_administrator: 'true'
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ services:
class: '\Drupal\lightning_media\MediaHelper'
arguments:
- '@entity_type.manager'

lightning_media.route_subscriber:
class: '\Drupal\lightning_media\Routing\RouteSubscriber'
tags:
-
name: event_subscriber
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ function lightning_media_image_modules_installed(array $modules) {
function lightning_media_image_media_entity_type_info_alter(array &$types) {
$types['image']['input_match']['field_types'] = ['image'];
Override::pluginClass($types['image'], Image::class);

// When a media item that uses the Image plugin is embedded in a text editor,
// prefer the media_image display plugin.
// @see \Drupal\lightning_media\Form\EntityEmbedDialog::buildEmbedStep()
$types['image']['entity_embed_display'] = 'media_image';
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Drupal\lightning_media\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\entity_embed\Form\EntityEmbedDialog as BaseEntityEmbedDialog;
use Drupal\media_entity\MediaInterface;

class EntityEmbedDialog extends BaseEntityEmbedDialog {

/**
* {@inheritdoc}
*/
public function buildEmbedStep(array $form, FormStateInterface $form_state) {
$entity = $form_state->get('entity');
$element = $form_state->get('entity_element');
$input = $form_state->getUserInput();

// If we're working with an existing embed, $input['editor_object'] will be
// set, in which case we don't want to change anything (see ::buildForm()).
// Otherwise, if the entity being embedded is a media item, see if its type
// plugin has a preference regarding which display plugin to use.
if (empty($input['editor_object']) && $entity instanceof MediaInterface) {
$plugin_definition = $entity->getType()->getPluginDefinition();

if (isset($plugin_definition['entity_embed_display'])) {
$element['data-entity-embed-display'] = $plugin_definition['entity_embed_display'];
$form_state->set('entity_element', $element);
}
}

$form = parent::buildEmbedStep($form, $form_state);

// If the user can choose the display plugin, allow Lightning Media's
// settings to override that access.
$element = &$form['attributes']['data-entity-embed-display'];
if ($element['#access']) {
$element['#access'] = $this->config('lightning_media.settings')->get('entity_embed.choose_display');
}
return $form;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Drupal\lightning_media\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
* The settings form for controlling Lightning Media's behavior.
*/
class SettingsForm extends ConfigFormBase {

/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['lightning_media.settings'];
}

/**
* {@inheritdoc}
*/
public function getFormId() {
return 'lightning_media_settings_form';
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['choose_display'] = [
'#type' => 'checkbox',
'#title' => $this->t('Allow users to choose how to display embedded media'),
'#default_value' => $this->config('lightning_media.settings')->get('entity_embed.choose_display'),
];
return parent::buildForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('lightning_media.settings')
->set('entity_embed.choose_display', (bool) $form_state->getValue('choose_display'))
->save();

parent::submitForm($form, $form_state);
}

}
Loading

0 comments on commit 7b1456b

Please sign in to comment.