diff --git a/composer.json b/composer.json
index 4ace769..21c3f68 100644
--- a/composer.json
+++ b/composer.json
@@ -38,7 +38,5 @@
"minimum-stability": "dev",
"require": {
"drupal/ctools": ">=3.0.0-beta1",
- "drupal/panels": ">=4.0.0-alpha1",
- "drupal/panels_ipe": ">=4.0.0-alpha1"
}
}
diff --git a/config/schema/flexilayout_builder.schema.yml b/config/schema/flexilayout_builder.schema.yml
new file mode 100644
index 0000000..1be1ef9
--- /dev/null
+++ b/config/schema/flexilayout_builder.schema.yml
@@ -0,0 +1,15 @@
+core.entity_view_display.*.*.*.third_party.panelizer:
+ type: mapping
+ label: 'Per-view-mode Flexible Layout Builder settings'
+ mapping:
+ static_context:
+ type: sequence
+ label: Static context list
+ sequence:
+ - type: ctools.context
+ label: 'Static Context'
+ relationships:
+ type: sequence
+ sequence:
+ - type: ctools.relationship
+ label: 'Relationship'
diff --git a/config/schema/panelizer.schema.yml b/config/schema/panelizer.schema.yml
deleted file mode 100644
index 8b873a9..0000000
--- a/config/schema/panelizer.schema.yml
+++ /dev/null
@@ -1,33 +0,0 @@
-# Config schema for Panelizer.
-panelizer.default.display:
- type: display_variant.plugin.panels_variant
- label: 'Panelizer display default'
- mapping:
- static_context:
- type: ctools.context
- label: 'Contexts'
- pattern:
- type: string
- label: 'Pattern plugin ID'
-
-core.entity_view_display.*.*.*.third_party.panelizer:
- type: mapping
- mapping:
- enable:
- type: boolean
- description: 'Is Panelizer enabled?'
- custom:
- type: boolean
- description: 'Are custom overrides allowed?'
- allow:
- type: boolean
- description: 'Is choosing between available defaults during entity creation allowed?'
- default:
- type: string
- description: 'Default display ID'
- displays:
- type: sequence
- description: 'Default displays'
- sequence:
- type: panelizer.default.display
- description: 'Default displays'
diff --git a/css/panelizer.admin.css b/css/panelizer.admin.css
deleted file mode 100644
index 1aa3794..0000000
--- a/css/panelizer.admin.css
+++ /dev/null
@@ -1,113 +0,0 @@
-/**
- * @file
- * Styles for Panelizer wizard admin.
- */
-
-/* Narrow screens */
-
-.panelizer-wizard-tree,
-.panelizer-wizard-form {
- box-sizing: border-box;
-}
-
-/**
- * Wizard actions across the top.
- */
-.panelizer-wizard-actions {
- text-align: right; /* LTR */
-}
-.panelizer-wizard-actions ul.inline,
-.panelizer-wizard-actions ul.inline li {
- display: inline-block;
- margin: 0;
-}
-.panelizer-wizard-actions ul.inline {
- border-top: 1px solid black;
- border-left: 1px solid black;
-}
-.panelizer-wizard-actions ul.inline li {
- border-right: 1px solid black;
- padding: .5em;
-}
-
-/**
- * The tree of wizard steps.
- */
-.panelizer-wizard-tree ul {
- margin: 0;
- padding: 0;
- list-style: none;
-}
-.panelizer-wizard-tree ul > li > ul {
- margin-left: 1em;
-}
-.panelizer-wizard-tree > ul {
- border: 1px solid black;
- padding-bottom: .5em;
- margin-bottom: 20px;
-}
-.panelizer-wizard-tree li {
- border-bottom: 1px solid black;
- padding: .5em;
- padding-right: 0;
-}
-.panelizer-wizard-tree li:last-child {
- border-bottom: 0;
- padding-bottom: 0;
-}
-
-/**
- * The wizard form.
- */
-.panelizer-wizard-form {
- border: 1px solid black;
- padding: 1em;
- margin-bottom: 20px;
-}
-
-/* Wide screens */
-@media
- screen and (min-width: 780px),
- (orientation: landscape) and (min-device-height: 780px) {
-
- /**
- * Overall layout.
- */
- .panelizer-wizard-tree {
- float: left; /* LTR */
- width: 20%;
- }
- .panelizer-wizard-form {
- float: left; /* LTR */
- width: 80%;
- }
- .panelizer-wizard-form-actions {
- margin-left: 20%; /* LTR */
- }
-
- /**
- * Make the borders look nice.
- */
- .panelizer-wizard-tree > ul {
- border-right: 0; /* LTR */
- }
- .panelizer-wizard-form {
- min-height: 400px;
- }
-
- /**
- * Right-to-left support.
- */
- [dir="rtl"] .panelizer-wizard-tree,
- [dir="rtl"] .panelizer-wizard-form {
- float: right;
- }
- [dir="rtl"] .panelizer-wizard-form-actions {
- margin-left: 0;
- margin-right: 20%;
- }
- [dir="rtl"] .panelizer-wizard-tree > ul {
- border-right: 1px solid black;
- border-left: 0;
- }
-}
diff --git a/css/panels_ipe.css b/css/panels_ipe.css
deleted file mode 100644
index c5e26d2..0000000
--- a/css/panels_ipe.css
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * @file
- * Stylesheet for Panelizer IPE customizations.
- */
-
-.panelizer-ipe-save-button {
- display: inline-block;
- margin: 10px;
-}
-
-.ipe-icon.ipe-icon-revert:before {
- /* @todo: Make a new icon for revert! */
- content: "\e90a";
-}
-
-/* Show the cancel title so it easier to tell the difference from revert. */
-[data-tab-id="cancel"] .ipe-tab-title {
- display: inline;
-}
-
diff --git a/js/panelizer-default-form.js b/js/panelizer-default-form.js
deleted file mode 100644
index 76aafe8..0000000
--- a/js/panelizer-default-form.js
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * @file
- * Javascript for the Panelizer defaults page.
- */
-(function ($) {
- Drupal.behaviors.panelizer_default_form = {
- attach: function (context, settings) {
- var $panelizer_checkbox = $(':input[name="panelizer[enable]"]');
-
- function update_form() {
- var $core_form = $('#field-display-overview-wrapper');
- if ($panelizer_checkbox.is(':checked')) {
- $core_form.fadeOut();
- }
- else {
- $core_form.fadeIn();
- }
- }
-
- $panelizer_checkbox.once('panelizer-default-form').click(update_form);
- update_form();
- }
- };
-})(jQuery);
diff --git a/js/panels_ipe/panels_ipe.js b/js/panels_ipe/panels_ipe.js
deleted file mode 100644
index 36af774..0000000
--- a/js/panels_ipe/panels_ipe.js
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- * @file
- * Entry point for the Panelizer IPE customizations.
- */
-
-(function ($, _, Backbone, Drupal) {
-
- 'use strict';
-
- Drupal.panelizer = Drupal.panelizer || {};
-
- /**
- * @namespace
- */
- Drupal.panelizer.panels_ipe = {};
-
- /**
- * Make customizations to the Panels IPE for Panelizer.
- */
- Backbone.on('PanelsIPEInitialized', function() {
- // Disable the normal save event.
- Drupal.panels_ipe.app_view.stopListening(Drupal.panels_ipe.app.get('saveTab'), 'change:active');
-
- // Add a new revert tab model.
- if (drupalSettings.panelizer.user_permission.revert) {
- var revert_tab = new Drupal.panels_ipe.TabModel({title: 'Revert to default', id: 'revert'});
- Drupal.panels_ipe.app_view.tabsView.collection.add(revert_tab);
-
- // @todo: Put this into a proper view?
- Drupal.panels_ipe.app_view.listenTo(revert_tab, 'change:active', function () {
- var entity = drupalSettings.panelizer.entity;
- if (revert_tab.get('active') && !revert_tab.get('loading')) {
- if (confirm(Drupal.t('Are you sure you want to revert to default layout? All your layout changes will be lost for this node.'))) {
- // Remove our changes and refresh the page.
- revert_tab.set({loading: true});
- $.ajax({
- url: drupalSettings.path.baseUrl + 'admin/panelizer/panels_ipe/' + entity.entity_type_id + '/' + entity.entity_id + '/' + entity.view_mode + '/revert_to_default',
- data: {},
- type: 'POST'
- }).done(function (data) {
- location.reload();
- });
- }
- else {
- revert_tab.set('active', false, {silent: true});
- }
- }
- });
-
- // Hide the 'Revert to default' button if we're already on a default.
- if (drupalSettings.panels_ipe.panels_display.storage_type == 'panelizer_default') {
- revert_tab.set({hidden: true});
- }
- }
-
- // Hide the 'Revert to default' button if the user does not have permission.
- // if (!drupalSettings.panelizer.user_permission.revert) {
- // revert_tab.set({hidden: true});
- // }
-
- // Add a new view for the save button to the TabsView.
- var tabs = {
- model: Drupal.panels_ipe.app_view.model,
- tabsView: Drupal.panels_ipe.app_view.tabsView,
- };
- if (typeof revert_tab !== 'undefined') {
- tabs.revertTab = revert_tab;
- }
- Drupal.panels_ipe.app_view.tabsView.tabViews['save'] = new Drupal.panelizer.panels_ipe.SaveTabView(tabs);
- });
-
-}(jQuery, _, Backbone, Drupal));
diff --git a/js/panels_ipe/views/SaveTabView.js b/js/panels_ipe/views/SaveTabView.js
deleted file mode 100644
index 547c8ea..0000000
--- a/js/panels_ipe/views/SaveTabView.js
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * @file
- * Contains Drupal.panelizer.panels_ipe.SaveTabView.
- */
-
-(function ($, _, Backbone, Drupal) {
- 'use strict';
-
- Drupal.panelizer.panels_ipe.SaveTabView = Backbone.View.extend(/** @lends Drupal.panelizer.panels_ipe.SaveTabView# */{
-
- /**
- * @type {function}
- */
- template: function() {
- return '';
- },
-
- /**
- * @type {Drupal.panels_ipe.AppModel}
- */
- model: null,
-
- /**
- * @type {Drupal.panels_ipe.TabsView}
- */
- tabsView: null,
-
- /**
- * @type {Drupal.panels_ipe.TabModel}
- */
- revertTab: null,
-
- /**
- * @type {object}
- */
- events: {
- },
-
- /**
- * @type {function}
- */
- onClick: function () {
- if (this.model.get('saveTab').get('active')) {
- // Always save as a custom override.
- this.saveCustom();
- }
- },
-
- /**
- * @type {function}
- */
- saveCustom: function () {
- this._save('panelizer_field');
- },
-
- /**
- * @type {function}
- */
- _save: function (storage_type) {
- var self = this,
- layout = this.model.get('layout');
-
- // Give the backend enough information to save in the correct way.
- layout.set('panelizer_save_as', storage_type);
- layout.set('panelizer_entity', drupalSettings.panelizer.entity);
-
- if (this.model.get('saveTab').get('active')) {
- // Save the Layout and disable the tab.
- this.model.get('saveTab').set({loading: true, active: false});
- this.tabsView.render();
- layout.save().done(function () {
- self.model.get('saveTab').set({loading: false});
- self.model.set('unsaved', false);
-
- // Change the storage type and id for the next save.
- drupalSettings.panels_ipe.panels_display.storage_type = storage_type;
- drupalSettings.panels_ipe.panels_display.storage_id = drupalSettings.panelizer.entity[storage_type + '_storage_id'];
- Drupal.panels_ipe.setUrlRoot(drupalSettings);
-
- // Show/hide the revert to default tab.
- if (self.revertTab) {
- self.revertTab.set({hidden: storage_type === 'panelizer_default'});
- }
- self.tabsView.render();
- });
- }
- },
-
- /**
- * @constructs
- *
- * @augments Backbone.View
- *
- * @param {Object} options
- * An object containing the following keys:
- * @param {Drupal.panels_ipe.AppModel} options.model
- * The app state model.
- * @param {Drupal.panels_ipe.TabsView} options.tabsView
- * The app view.
- * @param {Drupal.panels_ipe.TabModel} options.revertTab
- * The revert tab.
- */
- initialize: function (options) {
- this.model = options.model;
- this.tabsView = options.tabsView;
- this.revertTab = options.revertTab;
-
- this.listenTo(this.model.get('saveTab'), 'change:active', this.onClick);
- },
-
- /**
- * Renders the selection menu for picking Layouts.
- *
- * @return {Drupal.panelizer.panels_ipe.SaveTabView}
- * Return this, for chaining.
- */
- render: function () {
- this.$el.html(this.template());
- return this;
- }
-
- });
-
-}(jQuery, _, Backbone, Drupal));
diff --git a/panelizer.api.php b/panelizer.api.php
deleted file mode 100644
index 6d60a6e..0000000
--- a/panelizer.api.php
+++ /dev/null
@@ -1,30 +0,0 @@
-bundle() == 'page') {
- $view_mode = 'my_custom_view_mode';
- }
-}
-
-/**
- * @} End of "addtogroup hooks".
- */
\ No newline at end of file
diff --git a/panelizer.info.yml b/panelizer.info.yml
index eb30fde..17bafbb 100644
--- a/panelizer.info.yml
+++ b/panelizer.info.yml
@@ -1,16 +1,12 @@
type: module
name: Panelizer
-description: 'Allow any entity view mode to be rendered using a Panels display.'
+description: 'Provide panels-like features to layout builder'
package: Layout
version: VERSION
core: 8.x
dependencies:
# Core.
- drupal:layout_discovery
- # @todo Break the dependency on Field UI.
- - drupal:field_ui
+ - drupal:layout_builder
# Contrib
- ctools:ctools_block
- - panels:panels
- # @todo Allow editing without the IPE.
- - panels:panels_ipe
diff --git a/panelizer.install b/panelizer.install
deleted file mode 100644
index ba3925d..0000000
--- a/panelizer.install
+++ /dev/null
@@ -1,33 +0,0 @@
-listAll('core.entity_view_display.') as $entity_display_name) {
- $entity_display = $config_factory->getEditable($entity_display_name);
- if ($displays = $entity_display->get('third_party_settings.panelizer.displays')) {
- foreach ($displays as $display_name => $display) {
- if (isset($display['layout'])) {
- $new_layout = panels_convert_plugin_ids_to_layout_discovery($display['layout']);
- if ($new_layout) {
- $displays[$display_name]['layout'] = $new_layout;
- }
- }
- }
- $entity_display
- ->set('third_party_settings.panelizer.displays', $displays)
- // Mark the resulting configuration as trusted data. This avoids issues
- // with future schema changes.
- ->save(TRUE);
- }
- }
-}
diff --git a/panelizer.libraries.yml b/panelizer.libraries.yml
deleted file mode 100644
index 50b9c76..0000000
--- a/panelizer.libraries.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-panelizer_default_form:
- version: VERSION
- js:
- js/panelizer-default-form.js: {}
- dependencies:
- - core/jquery
- - core/jquery.once
-panels_ipe:
- version: VERSION
- js:
- # Core.
- js/panels_ipe/panels_ipe.js: {}
- # Views.
- js/panels_ipe/views/SaveTabView.js: {}
- css:
- component:
- css/panels_ipe.css: {}
- dependencies:
- - panels_ipe/panels_ipe
-wizard_admin:
- version: VERSION
- css:
- layout:
- css/panelizer.admin.css: {}
diff --git a/panelizer.links.action.yml b/panelizer.links.action.yml
deleted file mode 100644
index 6ed51fe..0000000
--- a/panelizer.links.action.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-panelizer.default.add:
- route_name: panelizer.wizard.add
- title: 'Add a new Panelizer default display'
- class: \Drupal\panelizer\Menu\AddDefaultLocalAction
- deriver: \Drupal\panelizer\Plugin\AddDefaultLinkDeriver
diff --git a/panelizer.module b/panelizer.module
index badc90d..512ba33 100644
--- a/panelizer.module
+++ b/panelizer.module
@@ -1,407 +1,167 @@
[
- 'render element' => 'element',
- ],
- 'panelizer_wizard_form' => [
- 'render element' => 'form',
- ],
- 'panelizer_wizard_tree' => [
- 'variables' => [
- 'wizard' => NULL,
- 'cached_values' => [],
- 'tree' => [],
- 'divider' => ' ยป ',
- 'step' => NULL,
- ],
- ],
- ];
+function panelizer_entity_type_alter(array &$entity_types) {
+ $entity_types['entity_view_display']
+ ->setClass(FlexibleLayoutBuilderEntityViewDisplay::class);
}
/**
- * Implements hook_entity_type_alter().
+ * Implements hook_element_info_alter
+ *
+ * The pre_render callback added here adds a "Manage Context" link to the interface
+ * that allows the addition of static contexts and relationships.
+ *
+ * @param array $info
*/
-function panelizer_entity_type_alter(array &$entity_types) {
- /** @var \Drupal\panelizer\Plugin\PanelizerEntityManager $panelizer_manager */
- $panelizer_manager = \Drupal::service('plugin.manager.panelizer_entity');
-
- // Replace the entity view builder on any entity where we have a Panelizer
- // entity plugin and the entity itself has a view builder.
- foreach ($panelizer_manager->getDefinitions() as $entity_type_id => $panelizer_info) {
- if (isset($entity_types[$entity_type_id]) && $entity_types[$entity_type_id]->hasHandlerClass('view_builder')) {
- $entity_types[$entity_type_id]->setHandlerClass('fallback_view_builder', $entity_types[$entity_type_id]->getHandlerClass('view_builder'));
- $entity_types[$entity_type_id]->setHandlerClass('view_builder', '\Drupal\panelizer\PanelizerEntityViewBuilder');
- }
- }
+function panelizer_element_info_alter(array &$info) {
+ $info['layout_builder']['#pre_render'][] = 'panelizer_layout_builder_context_control_pre_render';
}
/**
- * Implements hook_panels_build_alter().
+ * Implements hook_layout_builder_section_storage().
+ *
+ * We change the default section storage class to make sure we can store layout
+ * wide third party settings.
*/
-function panelizer_panels_build_alter(&$build, PanelsDisplayVariant $panels_display) {
- $builder = $panels_display->getBuilder();
- $storage_type = $panels_display->getStorageType();
-
- $is_panelizer = $builder->getPluginId() == 'ipe' &&
- in_array($storage_type, ['panelizer_default', 'panelizer_field']) &&
- isset($build['#attached']) &&
- isset($build['#attached']['library']) &&
- in_array('panels_ipe/panels_ipe', $build['#attached']['library']);
-
- // Add our Javascript customizations for the IPE.
- if ($is_panelizer) {
- $build['#attached']['library'][] = 'panelizer/panels_ipe';
-
- /** @var \Drupal\Core\Entity\EntityInterface $entity */
- $entity = $panels_display->getContexts()['@panelizer.entity_context:entity']->getContextValue();
- $revision_id = ($entity instanceof RevisionableInterface && $entity->getEntityType()->isRevisionable()) && !$entity->isDefaultRevision() ? $entity->getRevisionId() : NULL;
- list (,, $view_mode) = explode(':', $panels_display->getStorageId());
-
- // Get the default storage id, if we're looking at a panelizer default or
- // the panelizer field contains a revision.
- if (sizeof(explode(':', $panels_display->getStorageId())) == 4) {
- list(, , , $default) = explode(':', $panels_display->getStorageId());
- }
- else {
- $default = NULL;
- }
- if ($panels_display->getStorageType() == 'panelizer_field') {
- $panelizer_default_storage_id = rtrim(implode(':', [$entity->getEntityTypeId(), $entity->bundle(), $view_mode, $default]), ':');
- }
- else {
- $panelizer_default_storage_id = $panels_display->getStorageId();
- }
-
- // Get the special, internal default storage id that includes the entity id,
- // which will allow us to correctly set the contexts on the Panels display.
- $panelizer_default_internal_storage_id = '*' . rtrim(implode(':', [$entity->getEntityTypeId(), $entity->id(), $view_mode, $default]), ':');
-
- // Get the custom storage id (omitting revision id if this is the default
- // revision).
- $panelizer_field_storage_id_parts = [$entity->getEntityTypeId(), $entity->id(), $view_mode];
- if ($revision_id) {
- $panelizer_field_storage_id_parts[] = $revision_id;
- }
- $panelizer_field_storage_id = implode(':', $panelizer_field_storage_id_parts);
-
- /** @var \Drupal\panelizer\PanelizerInterface $panelizer */
- $panelizer = \Drupal::service('panelizer');
-
- $build['#attached']['drupalSettings']['panelizer']['entity'] = [
- 'entity_type_id' => $entity->getEntityTypeId(),
- 'entity_id' => $entity->id(),
- 'view_mode' => $view_mode,
- 'revision_id' => $revision_id,
- 'panelizer_default_storage_id' => $panelizer->hasDefaultPermission('change content', $entity->getEntityTypeId(), $entity->bundle(), $view_mode, $default) ? $panelizer_default_internal_storage_id : FALSE,
- 'panelizer_field_storage_id' => $panelizer->hasEntityPermission('change content', $entity, $view_mode) ? $panelizer_field_storage_id : FALSE,
- 'panelizer_default_real_storage_id' => $panelizer_default_storage_id,
- ];
-
- // Whether or not the current user has access to the "revert to default"
- // action in the IPE; any user with the 'administer panelizer' will also
- // have access.
- $build['#attached']['drupalSettings']['panelizer']['user_permission']['revert'] = $panelizer->hasEntityPermission('revert to default', $entity, $view_mode);
-
- // Whether or not the current user has access to the "set as default" action
- // in the IPE; any user with the 'administer panelizer' will also have
- // access.
- $user = \Drupal::currentUser();
- $build['#attached']['drupalSettings']['panelizer']['user_permission']['save_default'] = $user->hasPermission('set panelizer default') || $user->hasPermission('administer panelizer');
+function panelizer_layout_builder_section_storage_alter(&$definitions) {
+ $definitions['defaults']->setClass(DefaultsSectionStorage::class);
+ $definitions['overrides']->setClass(OverridesSectionStorage::class);
+}
- if ($panels_display->getStorageType() == 'panelizer_field') {
- // If using panelizer_field, we change the storage id to match what we put
- // together here because it'll have the revision id omitted in the right
- // situation.
- $build['#attached']['drupalSettings']['panels_ipe']['panels_display']['storage_id'] = $panelizer_field_storage_id;
- }
- else {
- // If using panelizer_default, we need to switch to a the special,
- // internal storage id.
- $build['#attached']['drupalSettings']['panels_ipe']['panels_display']['storage_id'] = $panelizer_default_internal_storage_id;
- }
+/**
+ * Implements hook_builder_module_implements_alter().
+ */
+function panelizer_module_implements_alter(&$implementations, $hook) {
+ if ($hook === 'entity_type_alter') {
+ // Ensure that this module's implementation of hook_entity_type_alter() runs
+ // last so that our entity class is used for entity_view_Display entities.
+ $group = $implementations['panelizer'];
+ unset($implementations['panelizer']);
+ $implementations['panelizer'] = $group;
}
}
/**
- * Implements hook_panels_ipe_panels_display_presave().
+ * Pre render the layout builder interface to add the context controls.
*/
-function panelizer_panels_ipe_panels_display_presave(PanelsDisplayVariant $panels_display, array $layout_model) {
- if (empty($layout_model['panelizer_save_as'])) {
- return;
+function panelizer_layout_builder_context_control_pre_render($element) {
+ $section_storage = $element['#section_storage'];
+ if (!($section_storage instanceof LayoutThirdPartySettingsInterface)) {
+ return $element;
}
- // See if the user requested changing the storage type.
- $current_storage = $panels_display->getStorageType();
- $panelizer_save_as = $layout_model['panelizer_save_as'];
- if ($current_storage !== $panelizer_save_as) {
- $panelizer_entity = $layout_model['panelizer_entity'];
-
- // When actually saving, we want to use the real storage id for me the
- // Panelizer default.
- $panelizer_entity['panelizer_default_storage_id'] = $panelizer_entity['panelizer_default_real_storage_id'];
-
- // If we were custom and now we want to save to the default, we need to
- // save specially to the Panelizer field so that we can tell it we're on
- // a default.
- if ($panelizer_save_as == 'panelizer_default') {
- /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
- $entity_type_manager = \Drupal::service("entity_type.manager");
- $storage = $entity_type_manager->getStorage($panelizer_entity['entity_type_id']);
- $entity = $storage->load($panelizer_entity['entity_id']);
- if ($entity instanceof FieldableEntityInterface) {
- /** @var \Drupal\panelizer\PanelizerInterface $panelizer */
- $panelizer = \Drupal::service('panelizer');
- list (,,, $default_name) = explode(':', $panelizer_entity['panelizer_default_storage_id']);
- $panelizer->setPanelsDisplay($entity, $panelizer_entity['view_mode'], $default_name);
- }
- }
-
- // We need to generate a new UUID if we're creating a custom display.
- if ($current_storage == 'panelizer_default' && $panelizer_save_as == 'panelizer_field') {
- $configuration = $panels_display->getConfiguration();
- $configuration['uuid'] = \Drupal::service('uuid')->generate();
- $panels_display->setConfiguration($configuration);
- }
+ $element['layout_builder']['#weight'] = 100;
+ $element['context_controls'] = [
+ '#type' => 'container',
+ '#weight' => -100,
+ '#attributes' => [
+ 'id' => 'layout-builder--context-controls',
+ 'class' => ['layout-builder--context-controls'],
+ ],
+ ];
+ $element['context_controls']['manage_context'] = [
+ '#type' => 'link',
+ '#title' => t('Manage Context'),
+ '#url' => Url::fromRoute('panelizer.view_context', [
+ 'section_storage_type' => $section_storage->getStorageType(),
+ 'section_storage' => $section_storage->getStorageId(),
+ ]),
+ '#attributes' => [
+ 'class' => ['use-ajax'],
+ 'data-dialog-type' => 'dialog',
+ 'data-dialog-renderer' => 'off_canvas',
+ ],
+ ];
- // Set the new storage information.
- $panels_display->setStorage($panelizer_save_as, $panelizer_entity[$panelizer_save_as . '_storage_id']);
- }
+ return $element;
}
/**
* Implements hook_form_FORM_ID_alter().
*/
-function panelizer_form_entity_view_display_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {
- /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
- $form_object = $form_state->getFormObject();
- /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
- $display = $form_object->getEntity();
-
- /** @var \Drupal\panelizer\Plugin\PanelizerEntityManager $panelizer_manager */
- $panelizer_manager = \Drupal::service('plugin.manager.panelizer_entity');
- /** @var \Drupal\panelizer\PanelizerInterface $panelizer */
- $panelizer = \Drupal::service('panelizer');
-
- $entity_type_id = $display->getTargetEntityTypeId();
- $bundle = $display->getTargetBundle();
- $mode = $display->getMode();
-
- if ($panelizer_manager->hasDefinition($entity_type_id)) {
- $settings = $panelizer->getPanelizerSettings($entity_type_id, $bundle, $mode, $display);
-
- // Always put the field table below the Panelizer options.
- $form['fields']['#weight'] = 10;
-
- $form['panelizer'] = [
- '#tree' => TRUE,
- ];
- $form['panelizer']['enable'] = [
- '#type' => 'checkbox',
- '#title' => t('Panelize this view mode'),
- '#default_value' => isset($settings['enable']) ? $settings['enable'] : FALSE,
- ];
-
- $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
-
- $form['panelizer']['options'] = [
- '#type' => 'details',
- '#open' => TRUE,
- '#title' => t('Panelizer options'),
- '#states' => [
- 'visible' => [
- '#edit-panelizer-enable' => ['checked' => TRUE],
- ],
- ],
- '#parents' => ['panelizer'],
- ];
-
- $form['panelizer']['options']['custom'] = [
- '#type' => 'checkbox',
- '#title' => t('Allow each @entity to have its display customized', [
- '@entity' => $entity_type->getSingularLabel(),
- ]),
- '#default_value' => isset($settings['custom']) ? $settings['custom'] : FALSE,
- ];
- $form['panelizer']['options']['allow'] = [
- '#type' => 'checkbox',
- '#title' => t('Allow users to select which display to use'),
- '#description' => t('When multiple default displays are available for a view mode it can be useful to allow content creators to choose which display to use for an individual @entity.', [
- '@entity' => $entity_type->getSingularLabel(),
- ]) . '
' . t('To enable the choice to be enabled by users, make sure the panelizer field is visible in the Manage form display'),
- '#default_value' => isset($settings['allow']) ? $settings['allow'] : FALSE,
- ];
-
- // If this display mode is panelized, then show the available displays in a
- // table.
- if (!empty($settings['enable'])) {
- $form['#cache']['tags'][] = "panelizer_default:$entity_type_id:$bundle:$mode";
- $form['panelizer']['displays'] = [
- '#type' => 'table',
- '#caption' => t('Default displays available for this view mode'),
- '#header' => [t('Name'), t('Use as default'), t('Operations')],
- ];
- foreach ($display->getThirdPartySetting('panelizer', 'displays', []) as $machine_name => $panels_display) {
- // Reset operations when in the foreach loop.
- $operations = [];
- $display_name = $machine_name;
- $machine_name ="{$entity_type_id}__{$bundle}__{$mode}__$machine_name";
- $operations['edit'] = [
- 'title' => t('Edit'),
- 'url' => Url::fromRoute('panelizer.wizard.edit', ['machine_name' => $machine_name]),
- ];
- if ($settings['default'] != $display_name) {
- $operations['set_default'] = [
- 'title' => t('Use as default'),
- 'url' => Url::fromRoute('panelizer.default.select', ['machine_name' => $machine_name]),
- ];
- $operations['delete'] = [
- 'title' => t('Delete'),
- 'url' => Url::fromRoute('panelizer.default.delete', ['machine_name' => $machine_name]),
- ];
- }
- $form['panelizer']['displays'][$machine_name] = [
- 'label' => ['#markup' => $panels_display['label']],
- 'default' => ['#markup' => $settings['default'] == $display_name ? '✓' : ''],
- 'operations' => [
- 'data' => [
- '#type' => 'operations',
- '#links' => $operations,
- ]
- ]
- ];
- }
- $form['fields']['#access'] = FALSE;
- }
-
- $form['#attached']['library'][] = 'panelizer/panelizer_default_form';
- $form['actions']['submit']['#submit'][] = 'panelizer_form_entity_view_display_edit_submit';
- }
-}
-
-function panelizer_form_entity_view_display_edit_submit(&$form, FormStateInterface $form_state) {
- $rebuild = FALSE;
- /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
- $form_object = $form_state->getFormObject();
- /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
- $display = $form_object->getEntity();
- /** @var \Drupal\panelizer\Plugin\PanelizerEntityManager $panelizer_manager */
- $panelizer_manager = \Drupal::service('plugin.manager.panelizer_entity');
- /** @var \Drupal\panelizer\Panelizer $panelizer */
- $panelizer = \Drupal::service('panelizer');
-
- if ($panelizer_manager->hasDefinition($display->getTargetEntityTypeId())) {
- $settings = $panelizer->getPanelizerSettings($display->getTargetEntityTypeId(), $display->getTargetBundle(), $display->getMode(), $display);
- if ($settings['enable'] != $form_state->getValue(['panelizer', 'enable'])) {
- $rebuild = TRUE;
- }
- $settings['enable'] = $form_state->getValue(['panelizer', 'enable']);
- $settings['custom'] = $form_state->getValue(['panelizer', 'custom']);
- $settings['allow'] = $form_state->getValue(['panelizer', 'allow']);
- $panelizer->setPanelizerSettings($display->getTargetEntityTypeId(), $display->getTargetBundle(), $display->getMode(), $settings, $display);
- if ($rebuild) {
- \Drupal::service('router.builder')->rebuild();
- /** @var \Drupal\Core\Menu\LocalActionManager $local_action_manager */
- $local_action_manager = \Drupal::service('plugin.manager.menu.local_action');
- $local_action_manager->clearCachedDefinitions();
- // Manually reinitialize these.
- $local_action_manager->getDefinitions();
- \Drupal::service('cache.render')->invalidateAll();
- }
- }
+function panelizer_form_layout_builder_add_block_alter(array &$form, FormStateInterface $form_state) {
+ /** @var \Drupal\layout_builder\SectionStorageInterface $section_storage */
+ list($section_storage, $delta, $region, $plugin_id) = $form_state->getBuildInfo()['args'];
+ $form_state->set('section_storage', $section_storage);
+ $form_state->set('flb__component', $form_state->get('layout_builder__component'));
+ $form_state->set('flb__uuid', $form_state->get('layout_builder__component')->getUuid());
+ $form_state->set('flb__delta', $delta);
+
+ _panelizer_layout_builder_block_form_alter($form, $form_state);
}
/**
- * Implements hook_form_FORM_ID_alter() for field_ui_field_storage_add_form().
+ * Implements hook_form_FORM_ID_alter().
*/
-function panelizer_form_field_ui_field_storage_add_form_alter(&$form, FormStateInterface $form_state, $form_id) {
- // Hide the legacy Panelizer field.
- // @todo Remove the Panelizer field entirely.
- if (isset($form['add']['new_storage_type']['#options']['General']['panelizer'])) {
- unset($form['add']['new_storage_type']['#options']['General']['panelizer']);
- }
+function panelizer_form_layout_builder_update_block_alter(array &$form, FormStateInterface $form_state) {
+ /** @var \Drupal\layout_builder\SectionStorageInterface $section_storage */
+ list($section_storage, $delta, $region, $uuid) = $form_state->getBuildInfo()['args'];
+ $form_state->set('section_storage', $section_storage);
+ $form_state->set('flb__component', $section_storage->getSection($delta)->getComponent($uuid));
+ $form_state->set('flb__uuid', $uuid);
+ $form_state->set('flb__delta', $delta);
+
+ _panelizer_layout_builder_block_form_alter($form, $form_state);
}
/**
- * Preprocess function for panelizer-wizard-tree.html.twig.
+ * Add magical extra things to the block form.
+ *
+ * Currently supported magic:
+ * - block_classes
+ * - field_label_overrides
+ *
+ * Still to implement:
+ * - Visibility rules
+ * - Output styles
*/
-function template_preprocess_panelizer_wizard_tree(&$variables) {
- /** @var $wizard \Drupal\ctools\Wizard\FormWizardInterface|\Drupal\ctools\Wizard\EntityFormWizardInterface */
- $wizard = $variables['wizard'];
- $cached_values = $variables['cached_values'];
- $tree = $variables['tree'];
- $variables['step'] = $wizard->getStep($cached_values);
-
- foreach ($wizard->getOperations($cached_values) as $step => $operation) {
- $parameters = $wizard->getNextParameters($cached_values);
- // Override step to be the step we want.
- $parameters['step'] = $step;
+function _panelizer_layout_builder_block_form_alter(array &$form, FormStateInterface $form_state) {
+ $form['actions']['#weight'] = 1000;
+ $form['panelizer'] = [
+ '#type' => 'container',
+ ];
- // Fill in parents if there are breadcrumbs.
- $parent =& $tree;
- if (isset($operation['breadcrumbs'])) {
- foreach ($operation['breadcrumbs'] as $breadcrumb) {
- $breadcrumb_string = (string) $breadcrumb;
- if (!isset($parent[$breadcrumb_string])) {
- $parent[$breadcrumb_string] = [
- 'title' => $breadcrumb,
- 'children' => [],
- ];
- }
- $parent =& $parent[$breadcrumb_string]['children'];
- }
- }
+ $class = $form_state->get('flb__component') ? $form_state->get('flb__component')->get('class') : '';
+ $form['panelizer']['class'] = [
+ '#type' => 'textfield',
+ '#title' => t('Block Classes'),
+ '#default_value' => $class,
+ ];
- $parent[$step] = [
- 'title' => !empty($operation['title']) ? $operation['title'] : '',
- 'url' => new Url($wizard->getRouteName(), $parameters),
- 'step' => $step,
+ /** @var \Drupal\layout_builder\SectionComponent $component */
+ if (($component = $form_state->get('flb__component')) && ($component->getPlugin() instanceof EntityField || $component->getPlugin() instanceof FieldBlock)) {
+ $form['panelizer']['field_label_override'] = [
+ '#type' => 'checkbox',
+ '#title' => t('Use Block Title as Field Label'),
+ '#default_value' => $component->get('field_label_override'),
];
}
- $variables['tree'] = $tree;
+ array_unshift($form['#submit'], '_panelizer_layout_builder_block_form_submit');
}
/**
- * Preprocess function for panelizer-view-mode.html.twig
- *
- * Prepare variables for Panelizer view mode templates.
+ * Submit.
*/
-function template_preprocess_panelizer_view_mode(&$variables) {
- $element = $variables['element'];
-
- // Copy values into the variables.
- /** @var \Drupal\panelizer\Plugin\PanelizerEntityInterface $panelizer_plugin */
- $panelizer_plugin = $variables['panelizer_plugin'] = $element['#panelizer_plugin'];
- /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display */
- $panels_display = $variables['panels_display'] = $element['#panels_display'];
- /** @var \Drupal\Core\Entity\EntityInterface $entity */
- $entity = $variables['entity'] = $element['#entity'];
- $view_mode = $variables['view_mode'] = $element['#view_mode'];
- $variables['content'] = $element['content'];
- $variables['title'] = isset($element['#title']) ? $element['#title'] : '';
-
- // Setup the defaults.
- $variables['title_element'] = 'h2';
- $variables['entity_url'] = $entity->toUrl('canonical', [
- 'language' => $entity->language(),
- ]);
-
- // Allow the Panelizer entity plugin to do additional preprocessing.
- $panelizer_plugin->preprocessViewMode($variables, $entity, $panels_display, $view_mode);
+function _panelizer_layout_builder_block_form_submit(array $form, FormStateInterface $form_state) {
+ $values = $form_state->getValue('panelizer');
+ $component = $form_state->get('section_storage')
+ ->getSection($form_state->get('flb__delta'))
+ ->getComponent($form_state->get('flb__uuid'));
+
+ $component->set('class', $values['class']);
+ $component->set('field_label_override', $values['field_label_override']);
}
-
diff --git a/panelizer.permissions.yml b/panelizer.permissions.yml
deleted file mode 100644
index 1fa7b0b..0000000
--- a/panelizer.permissions.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-administer panelizer:
- title: 'Administer Panelizer'
- description: 'Fully administer Panelizer and all Panelizer settings.'
-set panelizer default:
- title: 'Set Panelizer Default'
- description: 'Allow user to "Set as default" in the Panelizer IPE.'
-permission_callbacks:
- - panelizer:getPermissions
diff --git a/panelizer.routing.yml b/panelizer.routing.yml
index 5baf178..2fb58ca 100644
--- a/panelizer.routing.yml
+++ b/panelizer.routing.yml
@@ -1,89 +1,85 @@
-# Panels IPE
-panelizer.panels_ipe.revert_to_default:
- path: '/admin/panelizer/panels_ipe/{entity_type_id}/{entity}/{view_mode}/revert_to_default'
- options:
- parameters:
- entity:
- type: entity:{entity_type_id}
- defaults:
- _controller: '\Drupal\panelizer\Controller\PanelizerPanelsIPEController::revertToDefault'
- requirements:
- _method: 'POST'
- _permission: 'access panels in-place editing'
- _custom_access: '\Drupal\panelizer\Controller\PanelizerPanelsIPEController::accessRevertToDefault'
-
-# Wizard
-panelizer.wizard.add:
- path: '/admin/structure/panelizer/add/{entity_type_id}/{bundle}/{view_mode_name}'
- defaults:
- _wizard: '\Drupal\panelizer\Wizard\PanelizerAddWizard'
- _title: 'Panelizer Wizard'
- tempstore_id: 'panelizer.wizard'
- requirements:
- _panelizer_default_access: 'TRUE'
- _permission: 'administer panelizer'
-
-panelizer.wizard.add.step:
- path: '/admin/structure/panelizer/add/{machine_name}/{step}'
+panelizer.view_context:
+ path: '/layout_builder/view/context/{section_storage_type}/{section_storage}'
defaults:
- _wizard: '\Drupal\panelizer\Wizard\PanelizerAddWizard'
- _title: 'Panelizer Wizard'
- tempstore_id: 'panelizer.wizard'
+ _controller: '\Drupal\panelizer\Controller\ViewContextController::build'
requirements:
- _permission: 'administer panelizer'
-
-panelizer.wizard.edit:
- path: '/admin/structure/panelizer/edit/{machine_name}/{step}'
+ _permission: 'configure any layout'
+ _layout_builder_access: 'view'
+ options:
+ _admin_route: TRUE
+ parameters:
+ section_storage:
+ layout_builder_tempstore: TRUE
+panelizer.add_static_context:
+ path: '/layout_builder/add/static_context/{section_storage_type}/{section_storage}/{data_type}'
defaults:
- _wizard: '\Drupal\panelizer\Wizard\PanelizerEditWizard'
- _title: 'Panelizer Wizard'
- tempstore_id: 'panelizer.wizard'
- step: 'general'
+ _form: '\Drupal\panelizer\Form\AddStaticContext'
requirements:
- _permission: 'administer panelizer'
-
-panelizer.default.delete:
- path: '/admin/structure/panelizer/delete/{machine_name}'
+ _permission: 'configure any layout'
+ _layout_builder_access: 'view'
+ options:
+ _admin_route: TRUE
+ parameters:
+ section_storage:
+ layout_builder_tempstore: TRUE
+panelizer.choose_static_context:
+ path: '/layout_builder/choose/static_context/{section_storage_type}/{section_storage}'
defaults:
- _form: '\Drupal\panelizer\Form\PanelizerDefaultDelete'
- _title: 'Delete panelizer default'
+ _controller: '\Drupal\panelizer\Controller\ChooseStaticContextController::build'
requirements:
- _panelizer_field_ui_view_mode_access: 'TRUE'
- _custom_access: '\Drupal\panelizer\Access\PanelizerDefaultsDisplayAccess::isNotDefaultDisplay'
-
-panelizer.default.select:
- path: '/admin/structure/panelizer/set_default/{machine_name}'
+ _permission: 'configure any layout'
+ _layout_builder_access: 'view'
+ options:
+ _admin_route: TRUE
+ parameters:
+ section_storage:
+ layout_builder_tempstore: TRUE
+panelizer.edit_static_context:
+ path: '/layout_builder/edit/static_context/{section_storage_type}/{section_storage}/{machine_name}'
defaults:
- _form: '\Drupal\panelizer\Form\PanelizerDefaultSelect'
- _title: 'Set as default'
+ _form: '\Drupal\panelizer\Form\EditStaticContext'
requirements:
- _panelizer_field_ui_view_mode_access: 'TRUE'
- _custom_access: '\Drupal\panelizer\Access\PanelizerDefaultsDisplayAccess::isNotDefaultDisplay'
+ _permission: 'configure any layout'
+ _layout_builder_access: 'view'
+ options:
+ _admin_route: TRUE
+ parameters:
+ section_storage:
+ layout_builder_tempstore: TRUE
-# Contexts
-panelizer.wizard.step.context.add:
- path: '/admin/panelizer/wizard/{machine_name}/contexts/add/{context_id}'
+panelizer.add_relationship:
+ path: '/layout_builder/add/relationship/{section_storage_type}/{section_storage}/{plugin}'
defaults:
- _form: '\Drupal\panelizer\Form\PanelizerWizardContextConfigure'
- _title: 'Add custom context'
- tempstore_id: 'panelizer.wizard'
+ _form: '\Drupal\panelizer\Form\AddRelationship'
requirements:
- _permission: 'administer panelizer'
-
-panelizer.wizard.step.context.edit:
- path: '/admin/panelizer/wizard/{machine_name}/contexts/edit/{context_id}'
+ _permission: 'configure any layout'
+ _layout_builder_access: 'view'
+ options:
+ _admin_route: TRUE
+ parameters:
+ section_storage:
+ layout_builder_tempstore: TRUE
+panelizer.choose_relationship:
+ path: '/layout_builder/choose/relationship/{section_storage_type}/{section_storage}'
defaults:
- _form: '\Drupal\panelizer\Form\PanelizerWizardContextConfigure'
- _title: 'Edit context'
- tempstore_id: 'panelizer.wizard'
+ _controller: '\Drupal\panelizer\Controller\ChooseRelationshipController::build'
requirements:
- _permission: 'administer panelizer'
-
-panelizer.wizard.step.context.delete:
- path: '/admin/panelizer/wizard/{machine_name}/context/delete/{context_id}'
+ _permission: 'configure any layout'
+ _layout_builder_access: 'view'
+ options:
+ _admin_route: TRUE
+ parameters:
+ section_storage:
+ layout_builder_tempstore: TRUE
+panelizer.edit_relationship:
+ path: '/layout_builder/edit/relationship/{section_storage_type}/{section_storage}/{machine_name}'
defaults:
- _form: '\Drupal\panelizer\Form\PanelizerWizardContextDeleteForm'
- _title: 'Delete static context'
- tempstore_id: 'panelizer.wizard'
+ _form: '\Drupal\panelizer\Form\EditRelationship'
requirements:
- _permission: 'administer panelizer'
+ _permission: 'configure any layout'
+ _layout_builder_access: 'view'
+ options:
+ _admin_route: TRUE
+ parameters:
+ section_storage:
+ layout_builder_tempstore: TRUE
diff --git a/panelizer.services.yml b/panelizer.services.yml
index d36b86c..2f65af2 100644
--- a/panelizer.services.yml
+++ b/panelizer.services.yml
@@ -1,17 +1,6 @@
services:
- access_check.panelizer.view_mode:
- class: Drupal\panelizer\Access\ViewModeAccessCheck
- arguments: ['@access_check.field_ui.view_mode']
+ panelizer.render_block_component_subscriber:
+ class: Drupal\panelizer\EventSubscriber\BlockComponentRenderArray
+ arguments: ['@current_user']
tags:
- - { name: access_check, applies_to: _panelizer_field_ui_view_mode_access }
- plugin.manager.panelizer_entity:
- class: Drupal\panelizer\Plugin\PanelizerEntityManager
- parent: default_plugin_manager
- panelizer:
- class: Drupal\panelizer\Panelizer
- arguments: ['@entity_type.manager', '@entity_type.bundle.info', '@entity_field.manager', '@plugin.manager.field.field_type', '@module_handler', '@current_user', '@plugin.manager.panelizer_entity', '@panels.display_manager', '@string_translation', '@ctools.context_mapper']
- panelizer.default.access:
- class: Drupal\panelizer\Access\DefaultAccess
- arguments: ['@panelizer']
- tags:
- - { name: access_check, applies_to: _panelizer_default_access }
+ - { name: event_subscriber }
diff --git a/panelizer_quickedit/README.txt b/panelizer_quickedit/README.txt
deleted file mode 100644
index 284bb68..0000000
--- a/panelizer_quickedit/README.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-Panelizer Quick Edit
----------
-This module contains customizations which allow Panelized Entities to be edited
-inline with Quick Edit. It is separate from the Panelizer project as not all
-users need this functionality.
diff --git a/panelizer_quickedit/panelizer_quickedit.info.yml b/panelizer_quickedit/panelizer_quickedit.info.yml
deleted file mode 100644
index a4e194d..0000000
--- a/panelizer_quickedit/panelizer_quickedit.info.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-type: module
-name: Panelizer Quick Edit
-description: 'Enables Quick Edit to function normally when using Panelizer.'
-package: Layout
-version: VERSION
-core: 8.x
-dependencies:
- - panelizer:panelizer
- - drupal:quickedit
diff --git a/panelizer_quickedit/panelizer_quickedit.module b/panelizer_quickedit/panelizer_quickedit.module
deleted file mode 100644
index 44c19f0..0000000
--- a/panelizer_quickedit/panelizer_quickedit.module
+++ /dev/null
@@ -1,59 +0,0 @@
-getTranslationFromContext($entity, $langcode);
-
- // Grab the information required to re-render the entity_field block.
- $temp = str_replace('panelizer-', '', $view_mode_id);
- list($view_mode, $block_id) = explode('-block-id-', $temp);
-
- // Load the Panelizer display.
- /** @var \Drupal\panelizer\PanelizerInterface $panelizer */
- $panelizer = \Drupal::service('panelizer');
- $display = $panelizer->getPanelsDisplay($entity, $view_mode);
-
- /** @var \Drupal\ctools_block\Plugin\Block\EntityField $plugin */
- $plugin = $display->getBlock($block_id);
-
- // Set the appropriate Entity context and build the plugin.
- $plugin->setContextValue('entity', $entity);
- $build = $plugin->build();
-
- // Add our custom field view-mode in case the user wants to edit again.
- $build['field']['#view_mode'] = $view_mode_id;
-
- return $build;
-}
-
-/**
- * Implements hook_entity_view_alter().
- */
-function panelizer_quickedit_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
- // Explicitly add support for ctools_block by attaching a custom view-mode to
- // every Block that's about to be rendered.
- if (isset($build['#panels_display'])) {
- // We only support known Display Builders.
- $supported_plugins = ['ipe', 'standard'];
- if (in_array($build['#panels_display']->getBuilder()->getPluginId(), $supported_plugins)) {
- $region_names = Element::getVisibleChildren($build['content']);
- foreach ($region_names as $region_name) {
- $block_ids = Element::getVisibleChildren($build['content'][$region_name]);
- foreach ($block_ids as $block_id) {
- $block = &$build['content'][$region_name][$block_id];
- if (isset($block['#base_plugin_id']) && $block['#base_plugin_id'] === 'entity_field') {
- $view_mode = 'panelizer-' . $build['#view_mode'] . '-block-id-' . $block_id;
- $block['content']['field']['#view_mode'] = $view_mode;
- }
- }
- }
- }
- }
-}
diff --git a/panelizer_quickedit/tests/src/FunctionalJavascript/PanelizerQuickEditTest.php b/panelizer_quickedit/tests/src/FunctionalJavascript/PanelizerQuickEditTest.php
deleted file mode 100644
index 005668a..0000000
--- a/panelizer_quickedit/tests/src/FunctionalJavascript/PanelizerQuickEditTest.php
+++ /dev/null
@@ -1,159 +0,0 @@
-drupalCreateContentType(['type' => 'page', 'name' => 'Page']);
-
- // Add a plain text field for this content type.
- FieldStorageConfig::create([
- 'field_name' => 'test_field',
- 'entity_type' => 'node',
- 'type' => 'string',
- ])->save();
-
- FieldConfig::create([
- 'field_name' => 'test_field',
- 'label' => 'Test Field',
- 'entity_type' => 'node',
- 'bundle' => 'page',
- 'required' => FALSE,
- 'settings' => [],
- 'description' => '',
- ])->save();
-
- /** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $entity_form_display */
- $entity_form_display = \Drupal::entityTypeManager()
- ->getStorage('entity_form_display')
- ->load('node.page.default');
- $entity_form_display->setComponent('test_field')->save();
-
- /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $entity_display */
- $entity_display = \Drupal::entityTypeManager()
- ->getStorage('entity_view_display')
- ->load('node.page.default');
- $entity_display->setComponent('test_field')->save();
-
- // Create a privileged user.
- $user = $this->drupalCreateUser([
- 'access contextual links',
- 'access in-place editing',
- 'access content',
- 'administer node display',
- 'administer panelizer',
- 'create page content',
- 'edit any page content',
- ]);
- $this->drupalLogin($user);
-
- // Enable Panelizer for Articles.
- $this->drupalGet('admin/structure/types/manage/page/display');
- $this->assertResponse(200);
- $edit = [
- 'panelizer[enable]' => TRUE,
- ];
- $this->drupalPostForm(NULL, $edit, t('Save'));
- $this->assertResponse(200);
- }
-
- /**
- * Tests Quick Editing a Panelized Node.
- */
- public function testPanelizerQuickEdit() {
- /** @var \Drupal\panelizer\PanelizerInterface $panelizer */
- $panelizer = \Drupal::service('panelizer');
- $displays = $panelizer->getDefaultPanelsDisplays('node', 'page', 'default');
- $display = $displays['default'];
-
- // Find the "test_field" block.
- $block_id = FALSE;
- foreach ($display->getConfiguration()['blocks'] as $block) {
- if ($block['id'] === 'entity_field:node:test_field') {
- $block_id = $block['uuid'];
- }
- }
-
- // Make sure we found a valid UUID.
- $this->assertNotFalse($block_id);
-
- // Create an Article.
- $node = $this->drupalCreateNode([
- 'type' => 'page',
- 'test_field' => [
- 'value' => 'Change me',
- ],
- ]);
-
- // Visit the new node.
- $this->drupalGet('node/' . $node->id());
- $this->assertResponse(200);
-
- // This is the unique ID we append to normal Quick Edit field IDs.
- $panelizer_id = 'panelizer-full-block-id-' . $block_id;
-
- // Assemble common CSS selectors.
- $entity_selector = '[data-quickedit-entity-id="node/' . $node->id() . '"]';
- $field_selector = '[data-quickedit-field-id="node/' . $node->id() . '/test_field/' . $node->language()->getId() . '/' . $panelizer_id . '"]';
-
- // Wait until Quick Edit loads.
- $condition = "jQuery('" . $entity_selector . " .quickedit').length > 0";
- $this->assertJsCondition($condition, 10000);
-
- // Initiate Quick Editing.
- $this->triggerClick($entity_selector . ' [data-contextual-id] > button');
- $this->click($entity_selector . ' [data-contextual-id] .quickedit > a');
- $this->triggerClick($field_selector);
- $this->assertSession()->assertWaitOnAjaxRequest();
-
- // Trigger an edit with Javascript (this is a "contenteditable" element).
- $this->getSession()->executeScript("jQuery('" . $field_selector . "').text('Hello world').trigger('keyup');");
-
- // To prevent 403s on save, we re-set our request (cookie) state.
- $this->prepareRequest();
-
- // Save the change.
- $this->triggerClick('.quickedit-button.action-save');
- $this->assertSession()->assertWaitOnAjaxRequest();
-
- // Re-visit the node to make sure the edit worked.
- $this->drupalGet('node/' . $node->id());
- $this->assertResponse(200);
- $this->assertSession()->pageTextContains('Hello world');
- }
-
- /**
- * Clicks the element with the given CSS selector using event triggers.
- *
- * @todo Remove when https://github.com/jcalderonzumba/gastonjs/issues/19
- * is fixed. Currently clicking anchors/buttons with nested elements is not
- * possible.
- *
- * @param string $css_selector
- * The CSS selector identifying the element to click.
- */
- protected function triggerClick($css_selector) {
- $this->getSession()->executeScript("jQuery('" . $css_selector . "')[0].click()");
- }
-
-}
diff --git a/src/Access/DefaultAccess.php b/src/Access/DefaultAccess.php
deleted file mode 100644
index 45af311..0000000
--- a/src/Access/DefaultAccess.php
+++ /dev/null
@@ -1,48 +0,0 @@
-panelizer = $panelizer;
- }
-
- /**
- * Determines access to a default Panelizer layout.
- *
- * @param string $entity_type_id
- * The panelized entity type ID.
- * @param string $bundle
- * The panelized bundle ID.
- * @param string $view_mode_name
- * The panelized view mode ID.
- *
- * @return \Drupal\Core\Access\AccessResult
- */
- public function access($entity_type_id, $bundle, $view_mode_name) {
- $settings = $this->panelizer->getPanelizerSettings($entity_type_id, $bundle, $view_mode_name);
- return $settings['enable'] ? AccessResult::allowed() : AccessResult::forbidden();
- }
-
-}
diff --git a/src/Access/PanelizerDefaultsDisplayAccess.php b/src/Access/PanelizerDefaultsDisplayAccess.php
deleted file mode 100644
index 1e76a9b..0000000
--- a/src/Access/PanelizerDefaultsDisplayAccess.php
+++ /dev/null
@@ -1,34 +0,0 @@
-getPanelizerSettings($entity_type, $bundle, $view_mode);
- if ($settings['default'] != $default) {
- $access = AccessResult::allowed();
- }
- else {
- $access = AccessResult::forbidden();
- }
- return $access->addCacheTags(["panelizer_default:$entity_type:$bundle:$view_mode", "panelizer_default:$entity_type:$bundle:$view_mode:$default"]);
- }
-
-}
diff --git a/src/Access/PanelizerUIAccess.php b/src/Access/PanelizerUIAccess.php
deleted file mode 100644
index a58bdec..0000000
--- a/src/Access/PanelizerUIAccess.php
+++ /dev/null
@@ -1,18 +0,0 @@
-hasPermission('administer panelizer') ? AccessResult::allowed() : AccessResult::forbidden();
- }
-
-}
diff --git a/src/Access/ViewModeAccessCheck.php b/src/Access/ViewModeAccessCheck.php
deleted file mode 100644
index bb28110..0000000
--- a/src/Access/ViewModeAccessCheck.php
+++ /dev/null
@@ -1,61 +0,0 @@
-accessCheck = $access_check;
- }
-
- /**
- * Adapt the panelizer defaults access check to correspond to field ui.
- *
- * @param \Symfony\Component\Routing\Route $route
- * The original route definition.
- * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
- * The route matched.
- * @param \Drupal\Core\Session\AccountInterface $account
- * The current user's account.
- * @param string $machine_name
- * The machine name of the panelizer default.
- *
- * @return \Drupal\Core\Access\AccessResultInterface
- * @throws \Exception
- */
- public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $machine_name) {
- $parts = explode('__', $machine_name);
- if (count($parts) != 4) {
- throw new \Exception('The provided machine_name is not well formed.');
- }
- list($entity_type_id, $bundle, $view_mode) = $parts;
- $defaults = [
- 'entity_type_id' => $entity_type_id,
- ] + $route->getDefaults();
- $route->setDefaults($defaults);
- $route->setRequirement('_field_ui_view_mode_access', 'administer ' . $entity_type_id . ' display');
- return $this->accessCheck->access($route, $route_match, $account, $view_mode, $bundle);
- }
-
-}
diff --git a/src/Annotation/PanelizerEntity.php b/src/Annotation/PanelizerEntity.php
deleted file mode 100644
index 1452143..0000000
--- a/src/Annotation/PanelizerEntity.php
+++ /dev/null
@@ -1,18 +0,0 @@
-get('plugin.manager.ctools.relationship')
+ );
+ }
+
+ /**
+ * ChooseStaticContextController constructor.
+ *
+ * @param \Drupal\ctools\Plugin\RelationshipManagerInterface $relationship_manager
+ */
+ public function __construct(RelationshipManagerInterface $relationship_manager) {
+ $this->relationshipManager = $relationship_manager;
+ }
+
+ /**
+ * Provides the UI for choosing a new static context.
+ *
+ * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
+ * The section storage.
+ *
+ * @return array
+ * A render array.
+ */
+ public function build(SectionStorageInterface $section_storage) {
+ $build['#title'] = $this->t('Choose a relationship');
+ $build['#type'] = 'container';
+
+ $definitions = $this->relationshipManager->getDefinitionsForContexts($this->getAvailableContexts($section_storage));
+ foreach ($definitions as $plugin_id => $definition) {
+ list($category,) = explode(':', $plugin_id, 2);
+ if ($category == $plugin_id) {
+ if (!empty($definition['deriver'])) {
+ continue;
+ }
+ else {
+ $category = 'other';
+ }
+ }
+
+ if (!isset($definitions[$category])) {
+ $category = 'other';
+ }
+
+ if (empty($build[$category])) {
+ $build[$category] = [
+ '#type' => 'details',
+ '#title' => isset($definitions[$category]) ? $definitions[$category]['label'] : new TranslatableMarkup('Other'),
+ 'links' => [
+ '#theme' => 'links',
+ ]
+ ];
+ }
+
+ $link = [
+ 'title' => $definition['label'],
+ 'url' => Url::fromRoute('panelizer.add_relationship', [
+ 'section_storage_type' => $section_storage->getStorageType(),
+ 'section_storage' => $section_storage->getStorageId(),
+ 'plugin' => $plugin_id,
+ ]),
+ ];
+ if ($this->isAjax()) {
+ $link['attributes']['class'][] = 'use-ajax';
+ $link['attributes']['data-dialog-type'][] = 'dialog';
+ $link['attributes']['data-dialog-renderer'][] = 'off_canvas';
+ }
+ $build[$category]['links']['#links'][] = $link;
+ }
+
+ if (isset($build['other'])) {
+ $build['other']['#weight'] = 100;
+ }
+
+ return $build;
+ }
+}
diff --git a/src/Controller/ChooseStaticContextController.php b/src/Controller/ChooseStaticContextController.php
new file mode 100644
index 0000000..fa4f7cf
--- /dev/null
+++ b/src/Controller/ChooseStaticContextController.php
@@ -0,0 +1,102 @@
+get('typed_data_manager')
+ );
+ }
+
+ /**
+ * ChooseStaticContextController constructor.
+ *
+ * @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
+ */
+ public function __construct(TypedDataManagerInterface $typed_data_manager) {
+ $this->typedDataManager = $typed_data_manager;
+ }
+
+ /**
+ * Provides the UI for choosing a new static context.
+ *
+ * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
+ * The section storage.
+ *
+ * @return array
+ * A render array.
+ */
+ public function build(SectionStorageInterface $section_storage) {
+ $build['#title'] = $this->t('Choose a data type');
+ $build['#type'] = 'container';
+
+ $definitions = $this->typedDataManager->getDefinitions();
+ foreach ($definitions as $data_type => $definition) {
+ list($category,) = explode(':', $data_type, 2);
+ if ($category == $data_type) {
+ if (!empty($definition['deriver'])) {
+ continue;
+ }
+ else {
+ $category = 'other';
+ }
+ }
+
+ if (!isset($definitions[$category])) {
+ $category = 'other';
+ }
+
+ if (empty($build[$category])) {
+ $build[$category] = [
+ '#type' => 'details',
+ '#title' => isset($definitions[$category]) ? $definitions[$category]['label'] : new TranslatableMarkup('Other'),
+ 'links' => [
+ '#theme' => 'links',
+ ]
+ ];
+ }
+
+ $link = [
+ 'title' => $definition['label'],
+ 'url' => Url::fromRoute('panelizer.add_static_context', [
+ 'section_storage_type' => $section_storage->getStorageType(),
+ 'section_storage' => $section_storage->getStorageId(),
+ 'data_type' => $data_type,
+ ]),
+ ];
+ if ($this->isAjax()) {
+ $link['attributes']['class'][] = 'use-ajax';
+ $link['attributes']['data-dialog-type'][] = 'dialog';
+ $link['attributes']['data-dialog-renderer'][] = 'off_canvas';
+ }
+ $build[$category]['links']['#links'][] = $link;
+ }
+
+ if (isset($build['other'])) {
+ $build['other']['#weight'] = 100;
+ }
+
+ return $build;
+ }
+}
diff --git a/src/Controller/PanelizerPanelsIPEController.php b/src/Controller/PanelizerPanelsIPEController.php
deleted file mode 100644
index 6e14bc2..0000000
--- a/src/Controller/PanelizerPanelsIPEController.php
+++ /dev/null
@@ -1,99 +0,0 @@
-panelizer = $panelizer;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container) {
- return new static(
- $container->get('panelizer')
- );
- }
-
- /**
- * Reverts an entity view mode to a particular named default.
- *
- * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
- * The entity.
- * @param string $view_mode
- * The view mode.
- *
- * @return \Symfony\Component\HttpFoundation\Response
- * An empty response.
- *
- * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
- */
- public function revertToDefault(FieldableEntityInterface $entity, $view_mode) {
- // Get the bundle specific default display as a fallback.
- $settings = $this->panelizer->getPanelizerSettings($entity->getEntityTypeId(), $entity->bundle(), $view_mode);
- $default = $settings['default'];
- // Check the entity for a documented default to which we should revert.
- if ($entity->hasField('panelizer') && $entity->panelizer->first()) {
- foreach ($entity->panelizer as $item) {
- if ($item->view_mode == $view_mode && !empty($item->default)) {
- $default = $item->default;
- break;
- }
- }
- }
- // If we somehow ended up not having a default, throw an exception.
- if (empty($default)) {
- throw new BadRequestHttpException("Default name to revert to must be passed!");
- }
- $this->panelizer->setPanelsDisplay($entity, $view_mode, $default);
- return new Response();
- }
-
- /**
- * Custom access checker for reverting an entity view mode to a named default.
- *
- * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
- * The entity.
- * @param string $view_mode
- * The view mode.
- * @param \Drupal\Core\Session\AccountInterface $account
- * The user account.
- *
- * @return \Drupal\Core\Access\AccessResultInterface
- * The access result.
- */
- public function accessRevertToDefault(FieldableEntityInterface $entity, $view_mode, AccountInterface $account) {
- return AccessResult::allowedIf($this->panelizer->hasEntityPermission('revert to default', $entity, $view_mode, $account));
- }
-
-}
\ No newline at end of file
diff --git a/src/Controller/ViewContextController.php b/src/Controller/ViewContextController.php
new file mode 100644
index 0000000..f57edd5
--- /dev/null
+++ b/src/Controller/ViewContextController.php
@@ -0,0 +1,219 @@
+contextRepository = $context_repository;
+ }
+
+ /**
+ * Provides the UI for listing contexts.
+ *
+ * @param \Drupal\layout_builder\SectionStorageInterface $section_storage
+ * The section storage.
+ *
+ * @return array
+ * A render array.
+ */
+ public function build(DefaultsSectionStorageInterface $section_storage) {
+ $build['#title'] = $this->t('Available Contexts');
+ $build['#type'] = 'container';
+
+ $build['provided'] = [
+ '#type' => 'details',
+ '#title' => new TranslatableMarkup('Provided Contexts'),
+ 'table' => [
+ '#type' => 'table',
+ '#header' => [
+ new TranslatableMarkup('Context'),
+ new TranslatableMarkup('Name'),
+ new TranslatableMarkup('Type'),
+ ],
+ ],
+ ];
+
+ $provided_contexts = $this->getAvailableContexts($section_storage);
+ $static_contexts = $section_storage->getThirdPartySetting('panelizer', 'static_context') ?: [];
+ $relationships = $section_storage->getThirdPartySetting('panelizer', 'relationships') ?: [];
+ $provided_contexts = array_diff_key($provided_contexts, $static_contexts, $relationships);
+ foreach ($provided_contexts as $machine_name => $context) {
+ /** @var \Drupal\Core\Plugin\Context\ContextInterface $context */
+ $row = [
+ 'context' => [
+ '#type' => 'markup',
+ '#markup' => $context->getContextDefinition()->getLabel(),
+ ],
+ 'name' => [
+ '#type' => 'markup',
+ '#markup' => $machine_name,
+ ],
+ 'type' => [
+ '#type' => 'markup',
+ '#markup' => $context->getContextDefinition()->getDataType(),
+ ],
+ ];
+ $build['provided']['table'][$machine_name] = $row;
+ }
+
+ $build['static'] = [
+ '#type' => 'details',
+ '#title' => new TranslatableMarkup('Static Context'),
+ 'add_button' => [
+ '#type' => 'link',
+ '#title' => new TranslatableMarkup('Add Static Context'),
+ '#url' => Url::fromRoute('panelizer.choose_static_context', [
+ 'section_storage_type' => $section_storage->getStorageType(),
+ 'section_storage' => $section_storage->getStorageId(),
+ ])
+ ],
+ 'table' => [
+ '#type' => 'table',
+ '#header' => [
+ new TranslatableMarkup('Context'),
+ new TranslatableMarkup('Name'),
+ new TranslatableMarkup('Type'),
+ new TranslatableMarkup('Operations'),
+ ],
+ ],
+ ];
+ if ($this->isAjax()) {
+ $build['static']['add_button']['#attributes']['class'][] = 'use-ajax';
+ $build['static']['add_button']['#attributes']['data-dialog-type'][] = 'dialog';
+ $build['static']['add_button']['#attributes']['data-dialog-renderer'][] = 'off_canvas';
+ }
+ foreach ($static_contexts as $machine_name => $context) {
+ $links = [];
+ $links['edit'] = [
+ 'title' => new TranslatableMarkup('Edit'),
+ 'url' => Url::fromRoute('panelizer.edit_static_context', [
+ 'section_storage_type' => $section_storage->getStorageType(),
+ 'section_storage' => $section_storage->getStorageId(),
+ 'machine_name' => $machine_name,
+ ]),
+ ];
+
+ if ($this->isAjax()) {
+ $links['edit']['attributes']['class'][] = 'use-ajax';
+ $links['edit']['attributes']['data-dialog-type'][] = 'dialog';
+ $links['edit']['attributes']['data-dialog-renderer'][] = 'off_canvas';
+ }
+
+ $row = [
+ 'context' => [
+ '#markup' => $context['label'],
+ ],
+ 'name' => [
+ '#markup' => $machine_name,
+ ],
+ 'type' => [
+ '#markup' => $context['type'],
+ ],
+ 'operations' => [
+ '#type' => 'operations',
+ '#links' => $links,
+ ]
+ ];
+ $build['static']['table'][$machine_name] = $row;
+ }
+
+ $build['relationships'] = [
+ '#type' => 'details',
+ '#title' => new TranslatableMarkup('Related Context'),
+ 'add_button' => [
+ '#type' => 'link',
+ '#title' => new TranslatableMarkup('Add Related Context'),
+ '#url' => Url::fromRoute('panelizer.choose_relationship', [
+ 'section_storage_type' => $section_storage->getStorageType(),
+ 'section_storage' => $section_storage->getStorageId(),
+ ])
+ ],
+ 'table' => [
+ '#type' => 'table',
+ '#header' => [
+ new TranslatableMarkup('Relationship'),
+ new TranslatableMarkup('Name'),
+ new TranslatableMarkup('Type'),
+ new TranslatableMarkup('Operations'),
+ ],
+ ],
+ ];
+ if ($this->isAjax()) {
+ $build['relationships']['add_button']['#attributes']['class'][] = 'use-ajax';
+ $build['relationships']['add_button']['#attributes']['data-dialog-type'][] = 'dialog';
+ $build['relationships']['add_button']['#attributes']['data-dialog-renderer'][] = 'off_canvas';
+ }
+ foreach ($relationships as $machine_name => $context) {
+ $links = [];
+ $links['edit'] = [
+ 'title' => new TranslatableMarkup('Edit'),
+ 'url' => Url::fromRoute('panelizer.edit_relationship', [
+ 'section_storage_type' => $section_storage->getStorageType(),
+ 'section_storage' => $section_storage->getStorageId(),
+ 'machine_name' => $machine_name,
+ ]),
+ ];
+
+ if ($this->isAjax()) {
+ $links['edit']['attributes']['class'][] = 'use-ajax';
+ $links['edit']['attributes']['data-dialog-type'][] = 'dialog';
+ $links['edit']['attributes']['data-dialog-renderer'][] = 'off_canvas';
+ }
+
+ $row = [
+ 'context' => [
+ '#markup' => $context['label'],
+ ],
+ 'name' => [
+ '#markup' => $machine_name,
+ ],
+ 'type' => [
+ '#markup' => $context['type'],
+ ],
+ 'operations' => [
+ '#type' => 'operations',
+ '#links' => $links,
+ ]
+ ];
+ $build['relationships']['table'][$machine_name] = $row;
+ }
+
+ // @todo: Relationships
+
+ return $build;
+ }
+
+ /**
+ * Instantiates a new instance of this class.
+ *
+ * This is a factory method that returns a new instance of this class. The
+ * factory should pass any needed dependencies into the constructor of this
+ * class, but not the container itself. Every call to this method must return
+ * a new instance of this class; that is, it may not implement a singleton.
+ *
+ * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
+ * The service container this instance should use.
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('context.repository')
+ );
+ }
+}
diff --git a/src/Entity/PanelizerLayoutBuilderEntityViewDisplay.php b/src/Entity/PanelizerLayoutBuilderEntityViewDisplay.php
new file mode 100644
index 0000000..f798678
--- /dev/null
+++ b/src/Entity/PanelizerLayoutBuilderEntityViewDisplay.php
@@ -0,0 +1,97 @@
+getContextValues(
+ $this->getThirdPartySetting('panelizer', 'static_context', [])
+ );
+
+ /** @var \Drupal\ctools\Plugin\RelationshipManager $relationship_manager */
+ $relationship_manager = \Drupal::service('plugin.manager.ctools.relationship');
+ /** @var \Drupal\Core\Plugin\Context\ContextHandler $context_handler */
+ $context_handler = \Drupal::service('context.handler');
+
+ foreach ($this->getThirdPartySetting('panelizer', 'relationships', []) as $machine_name => $relationship) {
+ /** @var \Drupal\ctools\Plugin\RelationshipInterface $plugin */
+ $plugin = $relationship_manager->createInstance($relationship['plugin'], $relationship['settings'] ?: []);
+ $context_handler->applyContextMapping($plugin, $contexts);
+
+ $contexts[$machine_name] = $plugin->getRelationship();
+ }
+
+ return $contexts;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function addSectionField($entity_type_id, $bundle, $field_name) {
+ parent::addSectionField($entity_type_id, $bundle, $field_name);
+
+ // Add the layout settings field.
+ $settings_field_name = OverridesSectionStorage::SETTINGS_FIELD_NAME;
+ $field = FieldConfig::loadByName($entity_type_id, $bundle, $settings_field_name);
+ if (!$field) {
+ $field_storage = FieldStorageConfig::loadByName($entity_type_id, $settings_field_name);
+ if (!$field_storage) {
+ $field_storage = FieldStorageConfig::create([
+ 'entity_type' => $entity_type_id,
+ 'field_name' => $settings_field_name,
+ 'type' => 'layout_settings',
+ 'locked' => TRUE,
+ ]);
+ $field_storage->setTranslatable(FALSE);
+ $field_storage->save();
+ }
+
+ $field = FieldConfig::create([
+ 'field_storage' => $field_storage,
+ 'bundle' => $bundle,
+ 'label' => t('Layout Settings'),
+ ]);
+ $field->setTranslatable(FALSE);
+ $field->save();
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function removeSectionField($entity_type_id, $bundle, $field_name) {
+ $query = $this->entityTypeManager()->getStorage($this->getEntityTypeId())->getQuery()
+ ->condition('targetEntityType', $this->getTargetEntityTypeId())
+ ->condition('bundle', $this->getTargetBundle())
+ ->condition('mode', $this->getMode(), '<>')
+ ->condition('third_party_settings.layout_builder.allow_custom', TRUE);
+ $enabled = (bool) $query->count()->execute();
+ if (!$enabled && $field = FieldConfig::loadByName($entity_type_id, $bundle, $field_name)) {
+ $field->delete();
+ }
+ if (!$enabled && $field = FieldConfig::loadByName($entity_type_id, $bundle, OverridesSectionStorage::SETTINGS_FIELD_NAME)) {
+ $field->delete();
+ }
+ }
+
+}
diff --git a/src/EventSubscriber/BlockComponentRenderArray.php b/src/EventSubscriber/BlockComponentRenderArray.php
new file mode 100644
index 0000000..1278cd0
--- /dev/null
+++ b/src/EventSubscriber/BlockComponentRenderArray.php
@@ -0,0 +1,76 @@
+currentUser = $current_user;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getSubscribedEvents() {
+ $events[LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY] = ['onBuildRender', 0];
+ return $events;
+ }
+
+ /**
+ * Builds render arrays for block plugins and sets it on the event.
+ *
+ * @param \Drupal\layout_builder\Event\SectionComponentBuildRenderArrayEvent $event
+ * The section component render event.
+ */
+ public function onBuildRender(SectionComponentBuildRenderArrayEvent $event) {
+ $block = $event->getPlugin();
+ if (!$block instanceof BlockPluginInterface) {
+ return;
+ }
+
+ $component = $event->getComponent();
+ $build = $event->getBuild();
+ if ($component->get('class')) {
+ foreach (explode(' ', $component->get('class')) as $class) {
+ $build['#attributes']['class'][] = $class;
+ }
+ }
+
+ if ($block instanceof EntityField || $block instanceof FieldBlock) {
+ if ($component->get('field_label_override')) {
+ $build['content']['field']['#title'] = $component->get('configuration')['label'];
+ }
+ }
+ $event->setBuild($build);
+ }
+
+}
diff --git a/src/Exception/PanelizerException.php b/src/Exception/PanelizerException.php
deleted file mode 100644
index 3bd76d9..0000000
--- a/src/Exception/PanelizerException.php
+++ /dev/null
@@ -1,9 +0,0 @@
-get('class_resolver'),
+ $container->get('layout_builder.tempstore_repository'),
+ $container->get('plugin.manager.ctools.relationship'),
+ $container->get('plugin_form.factory')
+ );
+ }
+
+ /**
+ * AddStaticContext constructor.
+ *
+ * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
+ */
+ public function __construct(ClassResolverInterface $class_resolver, LayoutTempstoreRepositoryInterface $layout_tempstore_repository, RelationshipManagerInterface $relationship_manager, PluginFormFactoryInterface $plugin_form_factory) {
+ $this->classResolver = $class_resolver;
+ $this->layoutTempstoreRepository = $layout_tempstore_repository;
+ $this->relationshipManager = $relationship_manager;
+ $this->pluginFormFactory = $plugin_form_factory;
+ }
+
+ /**
+ * Returns a unique string identifying the form.
+ *
+ * The returned ID should be a unique string that can be a valid PHP function
+ * name, since it's used in hook implementation names such as
+ * hook_form_FORM_ID_alter().
+ *
+ * @return string
+ * The unique string identifying the form.
+ */
+ public function getFormId() {
+ return 'add_static_context_form';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildForm(array $form, FormStateInterface $form_state, DefaultsSectionStorageInterface $section_storage = NULL, $plugin = NULL) {
+ return $this->doBuildForm($form, $form_state, $section_storage, 'add', $plugin);
+ }
+
+ /**
+ * Form constructor.
+ *
+ * @param array $form
+ * An associative array containing the structure of the form.
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form.
+ *
+ * @return array
+ * The form structure.
+ */
+ public function doBuildForm(array $form, FormStateInterface $form_state, DefaultsSectionStorageInterface $section_storage = NULL, $op = 'edit', $plugin = NULL) {
+ $this->sectionStorage = $section_storage;
+
+ if ($op == 'edit') {
+ $relationships = $this->sectionStorage->getThirdPartySetting('panelizer', 'relationships');
+ $relationship_config = $relationships[$plugin];
+ $machine_name = $plugin;
+ $plugin = $relationship_config['plugin'];
+ $this->relationship = $this->relationshipManager->createInstance($relationship_config['plugin'], $relationship_config['settings'] ?: []);
+ }
+ else {
+ $this->relationship = $this->relationshipManager->createInstance($plugin);
+ $machine_name = NULL;
+ }
+
+
+ $form['#tree'] = TRUE;
+ $form['plugin'] = [
+ '#type' => 'value',
+ '#value' => $plugin,
+ ];
+ $form['label'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Label'),
+ '#required' => TRUE,
+ '#default_value' => isset($relationship_config['label']) ? $relationship_config['label'] : '',
+ ];
+ $form['machine_name'] = [
+ '#type' => 'machine_name',
+ '#title' => $this->t('Machine Name'),
+ '#required' => TRUE,
+ '#maxlength' => 128,
+ '#default_value' => $machine_name,
+ '#disabled' => !empty($machine_name),
+ '#machine_name' => [
+ 'source' => ['label'],
+ 'exists' => [$this, 'contextExists'],
+ ],
+ ];
+ $form['description'] = [
+ '#type' => 'textarea',
+ '#title' => $this->t('Description'),
+ '#default_value' => isset($relationship_config['description']) ? $relationship_config['description'] : '',
+ ];
+
+ if ($this->relationship instanceof ConfigurableRelationshipInterface) {
+ $subform_state = SubformState::createForSubform($form['settings'], $form, $form_state);
+ $form['settings'] = [];
+ $form['settings'] = $this->pluginFormFactory->createInstance($this->relationship, 'configure')->buildConfigurationForm($form['settings'], $subform_state);
+ }
+ else {
+ $form['settings'] = [
+ '#type' => 'container',
+ 'context_mapping' => $this->addContextAssignmentElement($this->relationship, $this->getAvailableContexts($this->sectionStorage)),
+ ];
+ }
+
+ $form['submit'] = [
+ '#type' => 'submit',
+ '#value' => $this->t('Add Relationship'),
+ '#button_type' => 'primary',
+ ];
+ if ($this->isAjax()) {
+ $form['submit']['#ajax']['callback'] = '::ajaxSubmit';
+ }
+
+ return $form;
+ }
+
+ /**
+ * @param $value
+ * @param array $element
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ *
+ * @return bool
+ */
+ public function contextExists($value, array $element, FormStateInterface $form_state) {
+ $static_context = $this->sectionStorage->getThirdPartySetting('panelizer','relationships');
+ return !empty($static_context[$value]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ if ($this->relationship instanceof ConfigurableRelationshipInterface) {
+ $subform_state = SubformState::createForSubform($form['settings'], $form,
+ $form_state);
+ $this->pluginFormFactory
+ ->createInstance($this->relationship, 'configure')
+ ->validateConfigurationForm($form['settings'], $subform_state);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitForm(array &$form, FormStateInterface $form_state) {
+ if ($this->relationship instanceof ConfigurableRelationshipInterface) {
+ // Call the plugin submit handler.
+ $subform_state = SubformState::createForSubform(
+ $form['settings'],
+ $form,
+ $form_state
+ );
+ $this->pluginFormFactory->createInstance($this->relationship, 'configure')
+ ->submitConfigurationForm(
+ $form,
+ $subform_state
+ );
+ $this->relationship->setContextMapping($subform_state->getValue('context_mapping', []));
+
+ $configuration = $this->relationship->getConfiguration();
+ }
+ else {
+ $configuration = $form_state->getValue('settings');
+ }
+
+ $values = $form_state->getValues();
+ $relationships = $this->sectionStorage->getThirdPartySetting('panelizer', 'relationships');
+ $relationships[$values['machine_name']] = [
+ 'plugin' => $values['plugin'],
+ 'label' => $values['label'],
+ 'description' => $values['description'],
+ 'settings' => $configuration,
+ ];
+ $this->sectionStorage->setThirdPartySetting('panelizer','relationships', $relationships);
+
+ $this->layoutTempstoreRepository->set($this->sectionStorage);
+ $form_state->setRedirectUrl($this->sectionStorage->getLayoutBuilderUrl());
+ }
+
+ /**
+ * Allows the form to respond to a successful AJAX submission.
+ *
+ * @param array $form
+ * An associative array containing the structure of the form.
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form.
+ *
+ * @return \Drupal\Core\Ajax\AjaxResponse
+ * An AJAX response.
+ */
+ protected function successfulAjaxSubmit(array $form, FormStateInterface $form_state) {
+ return $this->rebuildAndClose($this->sectionStorage);
+ }
+}
diff --git a/src/Form/AddStaticContext.php b/src/Form/AddStaticContext.php
new file mode 100644
index 0000000..86557d1
--- /dev/null
+++ b/src/Form/AddStaticContext.php
@@ -0,0 +1,190 @@
+get('class_resolver'),
+ $container->get('layout_builder.tempstore_repository')
+ );
+ }
+
+ /**
+ * AddStaticContext constructor.
+ *
+ * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
+ */
+ public function __construct(ClassResolverInterface $class_resolver, LayoutTempstoreRepositoryInterface $layout_tempstore_repository) {
+ $this->classResolver = $class_resolver;
+ $this->layoutTempstoreRepository = $layout_tempstore_repository;
+ }
+
+ /**
+ * Returns a unique string identifying the form.
+ *
+ * The returned ID should be a unique string that can be a valid PHP function
+ * name, since it's used in hook implementation names such as
+ * hook_form_FORM_ID_alter().
+ *
+ * @return string
+ * The unique string identifying the form.
+ */
+ public function getFormId() {
+ return 'add_static_context_form';
+ }
+
+ /**
+ * Form constructor.
+ *
+ * @param array $form
+ * An associative array containing the structure of the form.
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form.
+ *
+ * @return array
+ * The form structure.
+ */
+ public function buildForm(array $form, FormStateInterface $form_state, DefaultsSectionStorageInterface $section_storage = NULL, $data_type = NULL) {
+ $this->sectionStorage = $section_storage;
+
+ $form['data_type'] = [
+ '#type' => 'value',
+ '#value' => $data_type,
+ ];
+ $form['label'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Label'),
+ '#required' => TRUE,
+ ];
+ $form['machine_name'] = [
+ '#type' => 'machine_name',
+ '#title' => $this->t('Machine Name'),
+ '#required' => TRUE,
+ '#maxlength' => 128,
+ '#machine_name' => [
+ 'source' => ['label'],
+ 'exists' => [$this, 'contextExists'],
+ ],
+ ];
+ $form['description'] = [
+ '#type' => 'textarea',
+ '#title' => $this->t('Description'),
+ ];
+ if (strpos($data_type, 'entity:') === 0) {
+ list(, $entity_type) = explode(':', $data_type);
+ /** @var EntityAdapter $entity */
+ $form['context_value'] = [
+ '#type' => 'entity_autocomplete',
+ '#required' => TRUE,
+ '#target_type' => $entity_type,
+ '#title' => $this->t('Select entity'),
+ ];
+ }
+ else {
+ $form['context_value'] = [
+ '#title' => $this->t('Set a context value'),
+ '#type' => 'textfield',
+ '#required' => TRUE,
+ ];
+ }
+ $form['submit'] = [
+ '#type' => 'submit',
+ '#value' => $this->t('Add Context'),
+ '#button_type' => 'primary',
+ '#submit' => [
+ '::submitForm',
+ ],
+ ];
+ if ($this->isAjax()) {
+ $form['submit']['#ajax']['callback'] = '::ajaxSubmit';
+ }
+
+ return $form;
+ }
+
+ /**
+ * @param $value
+ * @param array $element
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ *
+ * @return bool
+ */
+ public function contextExists($value, array $element, FormStateInterface $form_state) {
+ $static_context = $this->sectionStorage->getThirdPartySetting('panelizer', 'static_context');
+ return !empty($static_context[$value]);
+ }
+
+ /**
+ * Form submission handler.
+ *
+ * @param array $form
+ * An associative array containing the structure of the form.
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form.
+ */
+ public function submitForm(array &$form, FormStateInterface $form_state) {
+ $values = $form_state->getValues();
+ $static_contexts = $this->sectionStorage->getThirdPartySetting('panelizer', 'static_context');
+ $static_contexts[$values['machine_name']] = [
+ 'type' => $values['data_type'],
+ 'label' => $values['label'],
+ 'description' => $values['description'],
+ 'value' => $values['context_value'],
+ ];
+ $this->sectionStorage->setThirdPartySetting('panelizer', 'static_context', $static_contexts);
+
+ dpm($this->sectionStorage);
+ dpm($this->sectionStorage->getThirdPartySettings('panelizer'));
+
+ $this->layoutTempstoreRepository->set($this->sectionStorage);
+ $form_state->setRedirectUrl($this->sectionStorage->getLayoutBuilderUrl());
+ }
+
+ /**
+ * Allows the form to respond to a successful AJAX submission.
+ *
+ * @param array $form
+ * An associative array containing the structure of the form.
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form.
+ *
+ * @return \Drupal\Core\Ajax\AjaxResponse
+ * An AJAX response.
+ */
+ protected function successfulAjaxSubmit(array $form, FormStateInterface $form_state) {
+ return $this->rebuildAndClose($this->sectionStorage);
+ }
+}
diff --git a/src/Form/EditRelationship.php b/src/Form/EditRelationship.php
new file mode 100644
index 0000000..0c50761
--- /dev/null
+++ b/src/Form/EditRelationship.php
@@ -0,0 +1,18 @@
+doBuildForm($form, $form_state, $section_storage, 'edit', $machine_name);
+ }
+
+}
diff --git a/src/Form/EditStaticContext.php b/src/Form/EditStaticContext.php
new file mode 100644
index 0000000..b77db02
--- /dev/null
+++ b/src/Form/EditStaticContext.php
@@ -0,0 +1,199 @@
+get('class_resolver'),
+ $container->get('layout_builder.tempstore_repository')
+ );
+ }
+
+ /**
+ * AddStaticContext constructor.
+ *
+ * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
+ */
+ public function __construct(ClassResolverInterface $class_resolver, LayoutTempstoreRepositoryInterface $layout_tempstore_repository) {
+ $this->classResolver = $class_resolver;
+ $this->layoutTempstoreRepository = $layout_tempstore_repository;
+ }
+
+ /**
+ * Returns a unique string identifying the form.
+ *
+ * The returned ID should be a unique string that can be a valid PHP function
+ * name, since it's used in hook implementation names such as
+ * hook_form_FORM_ID_alter().
+ *
+ * @return string
+ * The unique string identifying the form.
+ */
+ public function getFormId() {
+ return 'edit_static_context_form';
+ }
+
+ /**
+ * Form constructor.
+ *
+ * @param array $form
+ * An associative array containing the structure of the form.
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form.
+ *
+ * @return array
+ * The form structure.
+ */
+ public function buildForm(array $form, FormStateInterface $form_state, DefaultsSectionStorageInterface $section_storage = NULL, $machine_name = NULL) {
+ $this->sectionStorage = $section_storage;
+ $static_contexts = $this->sectionStorage->getThirdPartySetting('panelizer', 'static_context');
+ $context = $static_contexts[$machine_name];
+ $data_type = $context['type'];
+
+ $form['data_type'] = [
+ '#type' => 'value',
+ '#value' => $data_type,
+ ];
+ $form['label'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Label'),
+ '#required' => TRUE,
+ '#default_value' => $context['label'],
+ ];
+ $form['machine_name'] = [
+ '#type' => 'machine_name',
+ '#title' => $this->t('Machine Name'),
+ '#required' => TRUE,
+ '#default_value' => $machine_name,
+ '#disabled' => TRUE,
+ '#maxlength' => 128,
+ '#machine_name' => [
+ 'source' => ['label'],
+ 'exists' => [$this, 'contextExists'],
+ ],
+ ];
+ $form['description'] = [
+ '#type' => 'textarea',
+ '#title' => $this->t('Description'),
+ '#default_value' => $context['description'],
+ ];
+ if (strpos($data_type, 'entity:') === 0) {
+ list(, $entity_type) = explode(':', $data_type);
+ $context_object = new EntityLazyLoadContext(
+ new ContextDefinition($data_type, $context['label']),
+ \Drupal::service('entity.repository'),
+ $context['value']
+ );
+ /** @var EntityAdapter $entity */
+ $form['context_value'] = [
+ '#type' => 'entity_autocomplete',
+ '#required' => TRUE,
+ '#target_type' => $entity_type,
+ '#default_value' => $context_object->getContextValue(),
+ '#title' => $this->t('Select entity'),
+ ];
+ }
+ else {
+ $form['context_value'] = [
+ '#title' => $this->t('Set a context value'),
+ '#type' => 'textfield',
+ '#required' => TRUE,
+ ];
+ }
+ $form['submit'] = [
+ '#type' => 'submit',
+ '#value' => $this->t('Save Context'),
+ '#button_type' => 'primary',
+ ];
+ if ($this->isAjax()) {
+ $form['submit']['#ajax']['callback'] = '::ajaxSubmit';
+ }
+
+ return $form;
+ }
+
+ /**
+ * @param $value
+ * @param array $element
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ *
+ * @return bool
+ */
+ public function contextExists($value, array $element, FormStateInterface $form_state) {
+ $static_context = $this->sectionStorage->getThirdPartySetting('panelizer', 'static_context');
+ return !empty($static_context[$value]);
+ }
+
+ /**
+ * Form submission handler.
+ *
+ * @param array $form
+ * An associative array containing the structure of the form.
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form.
+ */
+ public function submitForm(array &$form, FormStateInterface $form_state) {
+ $values = $form_state->getValues();
+ $static_contexts = $this->sectionStorage->getThirdPartySetting('panelizer', 'static_context');
+ $static_contexts[$values['machine_name']] = [
+ 'type' => $values['data_type'],
+ 'label' => $values['label'],
+ 'description' => $values['description'],
+ 'value' => $values['context_value'],
+ ];
+ $this->sectionStorage->setThirdPartySetting('panelizer', 'static_context', $static_contexts);
+
+ $this->layoutTempstoreRepository->set($this->sectionStorage);
+ }
+
+ /**
+ * Allows the form to respond to a successful AJAX submission.
+ *
+ * @param array $form
+ * An associative array containing the structure of the form.
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form.
+ *
+ * @return \Drupal\Core\Ajax\AjaxResponse
+ * An AJAX response.
+ */
+ protected function successfulAjaxSubmit(array $form, FormStateInterface $form_state) {
+ return $this->rebuildAndClose($this->sectionStorage);
+ }
+}
diff --git a/src/Form/PanelizerDefaultDelete.php b/src/Form/PanelizerDefaultDelete.php
deleted file mode 100644
index fb96cc5..0000000
--- a/src/Form/PanelizerDefaultDelete.php
+++ /dev/null
@@ -1,170 +0,0 @@
-entityTypeManager = $entity_type_manager;
- $this->panelizer = $panelizer;
- $this->panelsDisplayManager = $panels_display_manager;
- $this->invalidator = $invalidator;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container) {
- return new static(
- $container->get('entity_type.manager'),
- $container->get('panelizer'),
- $container->get('panels.display_manager'),
- $container->get('cache_tags.invalidator')
- );
- }
-
- /**
- * {@inheritdoc}
- */
- public function getQuestion() {
- return 'Are you certain you want to delete this panelizer default?.';
- }
-
- /**
- * {@inheritdoc}
- */
- public function getCancelUrl() {
- $bundle_entity_type = $this->entityTypeManager->getDefinition($this->entityTypeId)->getBundleEntityType();
- if ($this->viewMode == 'default') {
- $route = "entity.entity_view_display.{$this->entityTypeId}.default";
- $arguments = [
- $bundle_entity_type => $this->bundle,
- ];
- }
- else {
- $route = "entity.entity_view_display.{$this->entityTypeId}.view_mode";
- $arguments = [
- $bundle_entity_type => $this->bundle,
- 'view_mode_name' => $this->viewMode,
- ];
- }
- return new Url($route, $arguments);
- }
-
- /**
- * {@inheritdoc}
- */
- public function getFormId() {
- return 'panelizer_default_delete';
- }
-
- /**
- * {@inheritdoc}
- */
- public function buildForm(array $form, FormStateInterface $form_state, $machine_name = NULL) {
- list (
- $this->entityTypeId,
- $this->bundle,
- $this->viewMode,
- $this->displayId
- ) = explode('__', $machine_name);
-
- return parent::buildForm($form, $form_state);
- }
-
- /**
- * {@inheritdoc}
- */
- public function submitForm(array &$form, FormStateInterface $form_state) {
- $display = $this->panelizer->getEntityViewDisplay($this->entityTypeId, $this->bundle, $this->viewMode);
- $displays = $this->panelizer->getDefaultPanelsDisplays($this->entityTypeId, $this->bundle, $this->viewMode, $display);
- unset($displays[$this->displayId]);
- foreach ($displays as $key => $value) {
- $displays[$key] = $this->panelsDisplayManager->exportDisplay($value);
- }
- $display->setThirdPartySetting('panelizer', 'displays', $displays);
- $display->save();
- $form_state->setRedirectUrl($this->getCancelUrl());
- $tag = "panelizer_default:{$this->entityTypeId}:{$this->bundle}:{$this->viewMode}:{$this->displayId}";
- $this->invalidator->invalidateTags([$tag]);
- }
-
-}
diff --git a/src/Form/PanelizerDefaultSelect.php b/src/Form/PanelizerDefaultSelect.php
deleted file mode 100644
index e1c98f1..0000000
--- a/src/Form/PanelizerDefaultSelect.php
+++ /dev/null
@@ -1,142 +0,0 @@
-panelizer = $panelizer;
- $this->invalidator = $invalidator;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container) {
- return new static(
- $container->get('panelizer'),
- $container->get('cache_tags.invalidator')
- );
- }
-
- /**
- * {@inheritdoc}
- */
- public function getQuestion() {
- return 'Are you certain you want to set this panelizer default as the default for this bundle?.';
- }
-
- /**
- * {@inheritdoc}
- */
- public function getCancelUrl() {
- $bundle_entity_type = \Drupal::entityTypeManager()->getDefinition($this->entityTypeId)->getBundleEntityType();
- if ($this->viewMode == 'default') {
- $route = "entity.entity_view_display.{$this->entityTypeId}.default";
- $arguments = [
- $bundle_entity_type => $this->bundle,
- ];
- }
- else {
- $route = "entity.entity_view_display.{$this->entityTypeId}.view_mode";
- $arguments = [
- $bundle_entity_type => $this->bundle,
- 'view_mode_name' => $this->viewMode,
- ];
- }
- return new Url($route, $arguments);
- }
-
- /**
- * {@inheritdoc}
- */
- public function getFormId() {
- return 'panelizer_default_delete';
- }
-
- /**
- * {@inheritdoc}
- */
- public function buildForm(array $form, FormStateInterface $form_state, $machine_name = NULL) {
- list (
- $this->entityTypeId,
- $this->bundle,
- $this->viewMode,
- $this->displayId
- ) = explode('__', $machine_name);
-
- return parent::buildForm($form, $form_state);
- }
-
- /**
- * {@inheritdoc}
- */
- public function submitForm(array &$form, FormStateInterface $form_state) {
- $display = $this->panelizer->getEntityViewDisplay($this->entityTypeId, $this->bundle, $this->viewMode);
- $settings = $this->panelizer->getPanelizerSettings($this->entityTypeId, $this->bundle, $this->viewMode, $display);
- $settings['default'] = $this->displayId;
- $this->panelizer->setPanelizerSettings($this->entityTypeId, $this->bundle, $this->viewMode, $settings, $display);
- $form_state->setRedirectUrl($this->getCancelUrl());
- $tag = "panelizer_default:{$this->entityTypeId}:{$this->bundle}:{$this->viewMode}";
- $this->invalidator->invalidateTags([$tag]);
- }
-
-}
diff --git a/src/Form/PanelizerWizardContextConfigure.php b/src/Form/PanelizerWizardContextConfigure.php
deleted file mode 100644
index a7ab050..0000000
--- a/src/Form/PanelizerWizardContextConfigure.php
+++ /dev/null
@@ -1,92 +0,0 @@
-contextMapper = $context_mapper;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container) {
- return new static(
- $container->get('user.shared_tempstore'),
- $container->get('ctools.context_mapper')
- );
- }
-
- /**
- * {@inheritdoc}
- */
- protected function getParentRouteInfo($cached_values) {
- return ['panelizer.wizard.add.step', [
- 'machine_name' => $cached_values['id'],
- 'step' => 'contexts',
- ]];
- }
-
- /**
- * {@inheritdoc}
- */
- protected function getContexts($cached_values) {
- $static_contexts = isset($cached_values['contexts']) ? $cached_values['contexts'] : [];
- $static_contexts = $this->contextMapper->getContextValues($static_contexts);
- return $static_contexts;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function addContext($cached_values, $context_id, ContextInterface $context) {
- $cached_values['contexts'][$context_id] = [
- 'label' => $context->getContextDefinition()->getLabel(),
- 'type' => $context->getContextDefinition()->getDataType(),
- 'description' => $context->getContextDefinition()->getDescription(),
- 'value' => strpos($context->getContextDefinition()->getDataType(), 'entity:') === 0 ? $context->getContextValue()->uuid() : $context->getContextValue(),
- ];
- return $cached_values;
- }
-
- /**
- * {@inheritdoc}
- */
- public function contextExists($value, $element, $form_state) {
- return FALSE;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function disableMachineName($cached_values, $machine_name) {
- return !empty($cached_values['contexts'][$machine_name]);
- }
-
-}
diff --git a/src/Form/PanelizerWizardContextDeleteForm.php b/src/Form/PanelizerWizardContextDeleteForm.php
deleted file mode 100644
index e4175e0..0000000
--- a/src/Form/PanelizerWizardContextDeleteForm.php
+++ /dev/null
@@ -1,54 +0,0 @@
-getTempstore();
- $context = $cached_values['contexts'][$this->context_id];
- return $this->t('Are you sure you want to delete the context @label?', ['@label' => $context['label']]);
- }
-
- /**
- * {@inheritdoc}
- */
- public function getCancelUrl() {
- $cached_values = $this->getTempstore();
-
- return new Url('panelizer.wizard.add.step', [
- 'machine_name' => $cached_values['id'],
- 'step' => 'contexts',
- ]);
- }
-
- /**
- * {@inheritdoc}
- */
- public function submitForm(array &$form, FormStateInterface $form_state) {
- $cached_values = $this->getTempstore();
- $context = $cached_values['contexts'][$this->context_id];
- drupal_set_message($this->t('The static context %label has been removed.', ['%label' => $context['label']]));
- unset($cached_values['contexts'][$this->context_id]);
- $this->setTempstore($cached_values);
- parent::submitForm($form, $form_state);
- }
-
-}
diff --git a/src/Form/PanelizerWizardContextForm.php b/src/Form/PanelizerWizardContextForm.php
deleted file mode 100644
index 44b6da7..0000000
--- a/src/Form/PanelizerWizardContextForm.php
+++ /dev/null
@@ -1,150 +0,0 @@
-get('typed_data_manager'),
- $container->get('form_builder'),
- $container->get('user.shared_tempstore')
- );
- }
-
- /**
- * ManageContext constructor.
- *
- * @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
- * The typed data manager.
- * @param \Drupal\Core\Form\FormBuilderInterface $form_builder
- * The form builder.
- * @param \Drupal\user\SharedTempStoreFactory $tempstore_factory
- * Shared user tempstore factory.
- */
- public function __construct(TypedDataManagerInterface $typed_data_manager, FormBuilderInterface $form_builder, SharedTempStoreFactory $tempstore_factory) {
- parent::__construct($typed_data_manager, $form_builder);
- $this->tempstoreFactory = $tempstore_factory;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getFormId() {
- return 'panelizer_wizard_context_form';
- }
-
- /**
- * {@inheritdoc}
- */
- protected function getContextClass($cached_values) {
- return PanelizerWizardContextConfigure::class;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function getRelationshipClass($cached_values) {}
-
- /**
- * {@inheritdoc}
- */
- protected function getContextAddRoute($cached_values) {
- return 'panelizer.wizard.step.context.add';
- }
-
- /**
- * {@inheritdoc}
- */
- protected function getRelationshipAddRoute($cached_values) {
- return 'panelizer.wizard.step.context.add';
- }
-
- /**
- * {@inheritdoc}
- */
- protected function getContexts($cached_values) {
- return $cached_values['plugin']->getPattern()->getDefaultContexts($this->tempstoreFactory, $this->getTempstoreId(), $this->machine_name);
- }
-
- /**
- * {@inheritdoc}
- */
- protected function getTempstoreId() {
- return 'panelizer.wizard';
- }
-
- /**
- * {@inheritdoc}
- */
- protected function getContextOperationsRouteInfo($cached_values, $machine_name, $row) {
- return ['panelizer.wizard.step.context', [
- 'machine_name' => $machine_name,
- 'context_id' => $row,
- ]];
- }
-
- /**
- * {@inheritdoc}
- */
- protected function getRelationshipOperationsRouteInfo($cached_values, $machine_name, $row) {
- return ['panelizer.wizard.step.context', [
- 'machine_name' => $machine_name,
- 'context_id' => $row,
- ]];
- }
-
- /**
- * {@inheritdoc}
- */
- protected function isEditableContext($cached_values, $row) {
- if (!isset($cached_values['contexts'][$row])) {
- return FALSE;
- }
- $context = $cached_values['contexts'][$row];
- return !empty($context['value']);
- }
-
- /**
- * {@inheritdoc}
- */
- public function addContext(array &$form, FormStateInterface $form_state) {
- $cached_values = $form_state->getTemporaryValue('wizard');
- $context = $form_state->getValue('context');
- $content = $this->formBuilder->getForm($this->getContextClass($cached_values), $context, $this->getTempstoreId(), $this->machine_name);
- $content['#attached']['library'][] = 'core/drupal.dialog.ajax';
- list(, $route_parameters) = $this->getContextOperationsRouteInfo($cached_values, $this->machine_name, $context);
- $content['submit']['#attached']['drupalSettings']['ajax'][$content['submit']['#id']]['url'] = $this->url($this->getContextAddRoute($cached_values), $route_parameters, ['query' => [FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]]);
- $response = new AjaxResponse();
- $response->addCommand(new OpenModalDialogCommand($this->t('Add new context'), $content, ['width' => '700']));
- return $response;
- }
-
-}
diff --git a/src/Form/PanelizerWizardGeneralForm.php b/src/Form/PanelizerWizardGeneralForm.php
deleted file mode 100644
index dcb84a9..0000000
--- a/src/Form/PanelizerWizardGeneralForm.php
+++ /dev/null
@@ -1,154 +0,0 @@
-routeMatch = $route_match;
-
- if ($route_match->getRouteName() == 'panelizer.wizard.add') {
- $this->entityTypeId = $route_match->getParameter('entity_type_id');
- $this->bundle = $route_match->getParameter('bundle');
- $this->viewMode = $route_match->getParameter('view_mode_name');
- }
- $this->panelizer = $panelizer;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container) {
- return new static(
- $container->get('current_route_match'),
- $container->get('panelizer')
- );
- }
-
- /**
- * {@inheritdoc}
- */
- public function getFormId() {
- return 'panelizer_wizard_general_form';
- }
-
- /**
- * @param $machine_name
- * @param $element
- */
- public static function validateMachineName($machine_name, $element) {
- // Attempt to load via the machine name and entity type.
- if (isset($element['#machine_name']['prefix'])) {
- $panelizer = \Drupal::service('panelizer');
- // Load the panels display variant.
- $full_machine_name = $element['#machine_name']['prefix'] . '__' . $machine_name;
- return $panelizer->getDefaultPanelsDisplayByMachineName($full_machine_name);
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function buildForm(array $form, FormStateInterface $form_state) {
- $cached_values = $form_state->getTemporaryValue('wizard');
- /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $plugin */
- $plugin = $cached_values['plugin'];
-
- $form_state = new FormState();
- $form_state->setValues($form_state->getValue('variant_settings', []));
- $settings = $plugin->buildConfigurationForm([], $form_state);
-
- // If the entity view display supports custom Panelizer layouts, force use
- // of the in-place editor. Right now, there is no other way to work with
- // custom layouts.
- if (isset($cached_values['id'])) {
- list ($this->entityTypeId, $this->bundle, $this->viewMode) = explode('__', $cached_values['id']);
- }
- $panelizer_settings = $this->panelizer
- ->getPanelizerSettings($this->entityTypeId, $this->bundle, $this->viewMode);
-
- if (!empty($panelizer_settings['custom'])) {
- $settings['builder']['#default_value'] = 'ipe';
- $settings['builder']['#access'] = FALSE;
- }
-
- $settings['#tree'] = TRUE;
- $form['variant_settings'] = $settings;
- return $form;
- }
-
- /**
- * {@inheritdoc}
- */
- public function validateForm(array &$form, FormStateInterface $form_state) {
- if ($form_state->hasValue('id') && !isset($this->machine_name) && $form_state->has('machine_name_prefix')) {
- $form_state->setValue('id', "{$form_state->get('machine_name_prefix')}__{$form_state->getValue('id')}");
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function submitForm(array &$form, FormStateInterface $form_state) {
- $cached_values = $form_state->getTemporaryValue('wizard');
- /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $plugin */
- $plugin = $cached_values['plugin'];
- $plugin->submitConfigurationForm($form['variant_settings'], (new FormState())->setValues($form_state->getValue('variant_settings', [])));
- $configuration = $plugin->getConfiguration();
- $cached_values['plugin']->setConfiguration($configuration);
- }
-
-}
diff --git a/src/LayoutThirdPartySettingsInterface.php b/src/LayoutThirdPartySettingsInterface.php
new file mode 100644
index 0000000..f5baf1a
--- /dev/null
+++ b/src/LayoutThirdPartySettingsInterface.php
@@ -0,0 +1,10 @@
+pluginDefinition['route_parameters']['entity_type_id'] = $route_match->getCurrentRouteMatch()->getParameter('entity_type_id');
- $this->pluginDefinition['route_parameters']['bundle'] = $route_match->getCurrentRouteMatch()->getParameter('bundle');
- $this->pluginDefinition['route_parameters']['view_mode_name'] = $route_match->getCurrentRouteMatch()->getParameter('view_mode_name');
- return parent::getRouteParameters($route_match);
- }
-
-}
diff --git a/src/Panelizer.php b/src/Panelizer.php
deleted file mode 100644
index 5169bb1..0000000
--- a/src/Panelizer.php
+++ /dev/null
@@ -1,688 +0,0 @@
-entityTypeManager = $entity_type_manager;
- $this->entityTypeBundleInfo = $entity_type_bundle_info;
- $this->entityFieldManager = $entity_field_manager;
- $this->fieldTypeManager = $field_type_manager;
- $this->moduleHandler = $module_handler;
- $this->currentUser = $current_user;
- $this->panelizerEntityManager = $panelizer_entity_manager;
- $this->panelsManager = $panels_manager;
- $this->stringTranslation = $string_translation;
- $this->contextMapper = $context_mapper;
- }
-
- /**
- * Gets the Panelizer entity plugin.
- *
- * @param $entity_type_id
- * The entity type id.
- *
- * @return \Drupal\panelizer\Plugin\PanelizerEntityInterface
- */
- protected function getEntityPlugin($entity_type_id) {
- return $this->panelizerEntityManager->createInstance($entity_type_id, []);
- }
-
- /**
- * Load a Panels Display via an ID (Machine Name).
- *
- * @return \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant|NULL
- * The default Panels display with the given name if it exists; otherwise
- * NULL.
- */
- public function getDefaultPanelsDisplayByMachineName($full_machine_name) {
- list($entity_type, $bundle, $view_mode, $machine_name) = explode('__', $full_machine_name);
- /** @var \Drupal\panelizer\Panelizer $panelizer */
- // @todo this $display_id looks all wrong to me since it's the name and view_mode.
- return $this->getDefaultPanelsDisplay($machine_name, $entity_type, $bundle, $view_mode);
- }
-
- /**
- * {@inheritdoc}
- */
- public function getEntityViewDisplay($entity_type_id, $bundle, $view_mode) {
- // Check the existence and status of:
- // - the display for the view mode,
- // - the 'default' display.
- $candidate_ids = [];
- if ($view_mode != 'default') {
- $candidate_ids[] = $entity_type_id . '.' . $bundle . '.' . $view_mode;
- }
- $candidate_ids[] = $entity_type_id . '.' . $bundle . '.default';
- $results = \Drupal::entityQuery('entity_view_display')
- ->condition('id', $candidate_ids)
- ->condition('status', TRUE)
- ->execute();
-
- // Select the first valid candidate display, if any.
- $load_id = FALSE;
- foreach ($candidate_ids as $candidate_id) {
- if (isset($results[$candidate_id])) {
- $load_id = $candidate_id;
- break;
- }
- }
-
- // Use the selected display if any, or create a fresh runtime object.
- $storage = $this->entityTypeManager->getStorage('entity_view_display');
- if ($load_id) {
- $display = $storage->load($load_id);
- }
- else {
- $display = $storage->create([
- 'targetEntityType' => $entity_type_id,
- 'bundle' => $bundle,
- 'mode' => $view_mode,
- 'status' => TRUE,
- ]);
- }
-
- // Let modules alter the display.
- $display_context = [
- 'entity_type' => $entity_type_id,
- 'bundle' => $bundle,
- 'view_mode' => $view_mode,
- ];
- $this->moduleHandler->alter('entity_view_display', $display, $display_context);
-
- return $display;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getPanelsDisplay(FieldableEntityInterface $entity, $view_mode, EntityViewDisplayInterface $display = NULL) {
- $settings = $this->getPanelizerSettings($entity->getEntityTypeId(), $entity->bundle(), $view_mode, $display);
- if (($settings['custom'] || $settings['allow']) && isset($entity->panelizer) && $entity->panelizer->first()) {
- /** @var \Drupal\Core\Field\FieldItemInterface[] $values */
- $values = [];
- foreach ($entity->panelizer as $item) {
- $values[$item->view_mode] = $item;
- }
- if (isset($values[$view_mode])) {
- $panelizer_item = $values[$view_mode];
- // Check for a customized display first and use that if present.
- if (!empty($panelizer_item->panels_display)) {
- // @todo: validate schema after https://www.drupal.org/node/2392057 is fixed.
- return $this->panelsManager->importDisplay($panelizer_item->panels_display, FALSE);
- }
- // If not customized, use the specified default.
- if (!empty($panelizer_item->default)) {
- // If we're using this magic key use the settings default.
- if ($panelizer_item->default == '__bundle_default__') {
- $default = $settings['default'];
- }
- else {
- $default = $panelizer_item->default;
- // Ensure the default still exists and if not fallback sanely.
- $displays = $this->getDefaultPanelsDisplays($entity->getEntityTypeId(), $entity->bundle(), $view_mode);
- if (!isset($displays[$default])) {
- $default = $settings['default'];
- }
- }
- $panels_display = $this->getDefaultPanelsDisplay($default, $entity->getEntityTypeId(), $entity->bundle(), $view_mode, $display);
- $this->setCacheTags($panels_display, $entity->getEntityTypeId(), $entity->bundle(), $view_mode, $display, $default, $settings);
- return $panels_display;
- }
- }
- }
- // If the field has no input to give us, use the settings default.
- $panels_display = $this->getDefaultPanelsDisplay($settings['default'], $entity->getEntityTypeId(), $entity->bundle(), $view_mode, $display);
- $this->setCacheTags($panels_display, $entity->getEntityTypeId(), $entity->bundle(), $view_mode, $display, $settings['default'], $settings);
- return $panels_display;
- }
-
- /**
- * Properly determine the cache tags for a display and set them.
- *
- * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
- * The panels display variant.
- * @param string $entity_type_id
- * The entity type id.
- * @param string $bundle
- * The bundle.
- * @param string $view_mode
- * The view mode.
- * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface|NULL $display
- * If the caller already has the correct display, it can optionally be
- * passed in here so the Panelizer service doesn't have to look it up;
- * otherwise, this argument can be omitted.
- * @param $default
- * The name of the panels display we are about to render.
- * @param array $settings
- * The default panelizer settings for this EntityViewDisplay.
- */
- protected function setCacheTags(PanelsDisplayVariant $panels_display, $entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL, $default, array $settings) {
- if (!$display) {
- $display = $this->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
- }
- $display_mode = $display ? $display->getMode() : '';
-
- if ($default == $settings['default']) {
- $tags = ["{$panels_display->getStorageType()}:{$entity_type_id}:{$bundle}:{$display_mode}"];
- }
- $tags[] = "{$panels_display->getStorageType()}:{$entity_type_id}:{$bundle}:{$display_mode}:$default";
- $panels_display->addCacheTags($tags);
- }
-
- /**
- * {@inheritdoc}
- */
- public function setPanelsDisplay(FieldableEntityInterface $entity, $view_mode, $default, PanelsDisplayVariant $panels_display = NULL) {
- $settings = $this->getPanelizerSettings($entity->getEntityTypeId(), $entity->bundle(), $view_mode);
- if (($settings['custom'] || $settings['allow']) && isset($entity->panelizer)) {
- $panelizer_item = NULL;
- /** @var \Drupal\Core\Field\FieldItemInterface $item */
- foreach ($entity->panelizer as $item) {
- if ($item->view_mode == $view_mode) {
- $panelizer_item = $item;
- break;
- }
- }
- if (!$panelizer_item) {
- $panelizer_item = $this->fieldTypeManager->createFieldItem($entity->panelizer, count($entity->panelizer));
- $panelizer_item->view_mode = $view_mode;
- }
-
- // Note: We don't call $panels_display->setStorage() here because it will
- // be set internally by PanelizerFieldType::postSave() which will know
- // the real revision ID of the newly saved entity.
-
- $panelizer_item->panels_display = $panels_display ? $this->panelsManager->exportDisplay($panels_display) : [];
- $panelizer_item->default = $default;
-
- // Create a new revision if possible.
- if ($entity instanceof RevisionableInterface && $entity->getEntityType()->isRevisionable()) {
- if ($entity->isDefaultRevision()) {
- $entity->setNewRevision(TRUE);
- }
- }
-
- // Updates the changed time of the entity, if necessary.
- if ($entity->getEntityType()->isSubclassOf(EntityChangedInterface::class)) {
- $entity->setChangedTime(REQUEST_TIME);
- }
-
- $entity->panelizer[$panelizer_item->getName()] = $panelizer_item;
-
- $entity->save();
- }
- else {
- throw new PanelizerException("Custom overrides not enabled on this entity, bundle and view mode");
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function getDefaultPanelsDisplays($entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL) {
- if (!$display) {
- $display = $this->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
- }
-
- // Get a list of all the defaults.
- $display_config = $display->getThirdPartySetting('panelizer', 'displays', []);
- $display_names = array_keys($display_config);
- if (empty($display_names)) {
- $display_names = ['default'];
- }
-
- // Get each one individually.
- $panels_displays = [];
- foreach ($display_names as $name) {
- if ($panels_display = $this->getDefaultPanelsDisplay($name, $entity_type_id, $bundle, $view_mode, $display)) {
- $panels_displays[$name] = $panels_display;
- }
- }
-
- return $panels_displays;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getDefaultPanelsDisplay($name, $entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL) {
- if (!$display) {
- $display = $this->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
- // If we still don't find a display, then we won't find a Panelizer
- // default for sure.
- if (!$display) {
- return NULL;
- }
- }
-
- $config = $display->getThirdPartySetting('panelizer', 'displays', []);
- if (!empty($config[$name])) {
- // Set a default just in case.
- $config[$name]['builder'] = empty($config[$name]['builder']) ? 'standard' : $config[$name]['builder'];
- // @todo: validate schema after https://www.drupal.org/node/2392057 is fixed.
- $panels_display = $this->panelsManager->importDisplay($config[$name], FALSE);
- }
- else {
- return NULL;
- }
-
- // @todo: Should be set when written, not here!
- $storage_id_parts = [
- $entity_type_id,
- $bundle,
- $view_mode,
- $name,
- ];
- $panels_display->setStorage('panelizer_default', implode(':', $storage_id_parts));
-
- return $panels_display;
- }
-
- /**
- * {@inheritdoc}
- */
- public function setDefaultPanelsDisplay($name, $entity_type_id, $bundle, $view_mode, PanelsDisplayVariant $panels_display) {
- $display = $this->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
- if (!$display) {
- throw new PanelizerException("Unable to find display for given entity type, bundle and view mode");
- }
-
- // Set this individual Panels display.
- $panels_displays = $display->getThirdPartySetting('panelizer', 'displays', []);
- $panels_displays[$name] = $this->panelsManager->exportDisplay($panels_display);
- $display->setThirdPartySetting('panelizer', 'displays', $panels_displays);
-
- $display->save();
- }
-
- /**
- * {@inheritdoc}
- */
- public function getDisplayStaticContexts($name, $entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL) {
- if (!$display) {
- $display = $this->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
- // If we still don't find a display, then we won't find a Panelizer
- // default for sure.
- if (!$display) {
- return NULL;
- }
- }
-
- $config = $display->getThirdPartySetting('panelizer', 'displays', []);
- if (!empty($config[$name]) && !empty($config[$name]['static_context'])) {
- return $this->contextMapper->getContextValues($config[$name]['static_context']);
- }
- return [];
- }
-
- /**
- * {@inheritdoc}
- */
- public function setDisplayStaticContexts($name, $entity_type_id, $bundle, $view_mode, $contexts) {
- $display = $this->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
- if (!$display) {
- throw new PanelizerException("Unable to find display for given entity type, bundle and view mode");
- }
-
- // Set this Panels display's static contexts.
- $panels_displays = $display->getThirdPartySetting('panelizer', 'displays', []);
- $panels_displays[$name]['static_context'] = $contexts;
- $display->setThirdPartySetting('panelizer', 'displays', $panels_displays);
-
- $display->save();
- }
-
- /**
- * {@inheritdoc}
- */
- public function isPanelized($entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL) {
- if (!$this->getEntityPlugin($entity_type_id)) {
- return FALSE;
- }
-
- if (!$display) {
- $display = $this->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
- }
-
- return $display->getThirdPartySetting('panelizer', 'enable', FALSE);
- }
-
- /**
- * {@inheritdoc}
- */
- public function getPanelizerSettings($entity_type_id, $bundle, $view_mode, EntityViewDisplayInterface $display = NULL) {
- if (!$display) {
- $display = $this->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
- }
-
- $settings = [
- 'enable' => $this->isPanelized($entity_type_id, $bundle, $view_mode, $display),
- 'custom' => $display->getThirdPartySetting('panelizer', 'custom', FALSE),
- 'allow' => $display->getThirdPartySetting('panelizer', 'allow', FALSE),
- 'default' => $display->getThirdPartySetting('panelizer', 'default', 'default'),
- ];
-
- // Make sure that the Panelizer field actually exists.
- if ($settings['custom']) {
- $fields = $this->entityFieldManager->getFieldDefinitions($entity_type_id, $bundle);
- $settings['custom'] = isset($fields['panelizer']) && $fields['panelizer']->getType() == 'panelizer';
- }
-
- return $settings;
- }
-
- /**
- * {@inheritdoc}
- */
- public function setPanelizerSettings($entity_type_id, $bundle, $view_mode, array $settings, EntityViewDisplayInterface $display = NULL) {
- if (!$display) {
- $display = $this->getEntityViewDisplay($entity_type_id, $bundle, $view_mode);
- }
-
- $display->setThirdPartySetting('panelizer', 'enable', !empty($settings['enable']));
- $display->setThirdPartySetting('panelizer', 'custom', !empty($settings['enable']) && !empty($settings['custom']));
- $display->setThirdPartySetting('panelizer', 'allow', !empty($settings['enable']) && !empty($settings['allow']));
- $display->setThirdPartySetting('panelizer', 'default', $settings['default']);
-
- if (!empty($settings['enable'])) {
- // Set the default display.
- $displays = $display->getThirdPartySetting('panelizer', 'displays', []);
- if (empty($displays['default'])) {
- /** @var \Drupal\panelizer\Plugin\PanelizerEntityInterface $panelizer_entity_plugin */
- $panelizer_entity_plugin = $this->panelizerEntityManager->createInstance($display->getTargetEntityTypeId(), []);
- $displays['default'] = $this->panelsManager->exportDisplay($panelizer_entity_plugin->getDefaultDisplay($display, $display->getTargetBundle(), $display->getMode()));
- $settings['default'] = "{$display->getTargetEntityTypeId()}__{$display->getTargetBundle()}__{$view_mode}__default";
- $display->setThirdPartySetting('panelizer', 'displays', $displays);
- }
-
- // Make sure the field exists.
- if (($settings['custom'] || $settings['allow'])) {
- $field_storage = $this->entityTypeManager->getStorage('field_storage_config')->load($entity_type_id . '.panelizer');
- if (!$field_storage) {
- $field_storage = $this->entityTypeManager->getStorage('field_storage_config')->create([
- 'entity_type' => $entity_type_id,
- 'field_name' => 'panelizer',
- 'type' => 'panelizer',
- 'cardinality' => -1,
- 'settings' => [],
- 'status' => TRUE,
- ]);
- $field_storage->save();
- }
-
- $field = $this->entityTypeManager->getStorage('field_config')->load($entity_type_id . '.' . $bundle . '.panelizer');
- if (!$field) {
- $field = $this->entityTypeManager->getStorage('field_config')->create([
- 'field_storage' => $field_storage,
- 'bundle' => $bundle,
- 'label' => $this->t('Panelizer'),
- 'settings' => [],
- ]);
- $field->save();
- }
- }
- }
-
- $display->save();
- }
-
- /**
- * Get a list of all the Panelizer operations.
- *
- * @return array
- * Associative array of the human-readable operation names, keyed by the
- * path.
- */
- protected function getOperations() {
- return [
- 'content' => $this->t('Content'),
- 'layout' => $this->t('Layout'),
- 'revert' => $this->t('Revert to default'),
- ];
- }
-
- /**
- * {@inheritdoc}
- */
- public function getPermissions() {
- $permissions = [];
-
- // Only look at entity types that have a corresponding Panelizer plugin.
- $entity_types = array_intersect_key(
- $this->entityTypeManager->getDefinitions(),
- $this->panelizerEntityManager->getDefinitions()
- );
-
- foreach ($entity_types as $entity_type_id => $entity_type) {
- $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id);
- foreach ($bundles as $bundle => $bundle_info) {
- $permissions["administer panelizer $entity_type_id $bundle defaults"] = [
- 'title' => t('%entity_name %bundle_name: Administer Panelizer default panels, allowed content and settings.', [
- '%entity_name' => $entity_type->getLabel(),
- '%bundle_name' => $bundle_info['label'],
- ]),
- 'description' => t('Users with this permission can fully administer panelizer for this entity bundle.'),
- ];
-
- foreach ($this->getOperations() as $path => $operation) {
- $permissions["administer panelizer $entity_type_id $bundle $path"] = [
- 'title' => $this->t('%entity_name %bundle_name: Administer Panelizer @operation', [
- '%entity_name' => $entity_type->getLabel(),
- '%bundle_name' => $bundle_info['label'],
- '@operation' => $operation,
- ]),
- ];
- }
- }
- }
-
- ksort($permissions);
- return $permissions;
- }
-
- /**
- * Check permission for an individual operation only.
- *
- * Doesn't check any of the baseline permissions that you need along with
- * the operation permission.
- *
- * @param string $op
- * The operation.
- * @param string $entity_type_id
- * The entity type id.
- * @param string $bundle
- * The bundle.
- * @param \Drupal\Core\Session\AccountInterface $account
- * The user account.
- *
- * @return bool
- * TRUE if the user has permission; FALSE otherwise.
- */
- protected function hasOperationPermission($op, $entity_type_id, $bundle, AccountInterface $account) {
- switch ($op) {
- case 'change content':
- return $account->hasPermission("administer panelizer $entity_type_id $bundle content");
-
- case 'change layout':
- return $account->hasPermission("administer panelizer $entity_type_id $bundle layout");
-
- case 'revert to default':
- return $account->hasPermission("administer panelizer $entity_type_id $bundle revert");
- }
-
- return FALSE;
- }
-
- /**
- * {@inheritdoc}
- */
- public function hasEntityPermission($op, EntityInterface $entity, $view_mode, AccountInterface $account = NULL) {
- if (!$account) {
- $account = $this->currentUser->getAccount();
- }
-
- // Must be able to edit the entity.
- if (!$entity->access('update', $account)) {
- return FALSE;
- }
-
- // Must have overrides enabled.
- $panelizer_settings = $this->getPanelizerSettings($entity->getEntityTypeId(), $entity->bundle(), $view_mode);
- if (empty($panelizer_settings['custom'])) {
- return FALSE;
- }
-
- // Check admin permission.
- if ($account->hasPermission('administer panelizer')) {
- return TRUE;
- }
-
- // @todo: check field access too!
-
- // if ($op == 'revert to default') {
- // // We already have enough permissions at this point.
- // return TRUE;
- // }
-
- return $this->hasOperationPermission($op, $entity->getEntityTypeId(), $entity->bundle(), $account);
- }
-
- /**
- * {@inheritdoc}
- */
- public function hasDefaultPermission($op, $entity_type_id, $bundle, $view_mode, $default, AccountInterface $account = NULL) {
- if (!$this->isPanelized($entity_type_id, $bundle, $view_mode)) {
- return FALSE;
- }
-
- if (!$account) {
- $account = $this->currentUser->getAccount();
- }
-
- // Check admin permissions.
- if ($account->hasPermission('administer panelizer')) {
- return TRUE;
- }
- if ($account->hasPermission("administer panelizer $entity_type_id $bundle defaults")) {
- return TRUE;
- }
-
- return $this->hasOperationPermission($op, $entity_type_id, $bundle, $account);
- }
-
-}
diff --git a/src/PanelizerEntityViewBuilder.php b/src/PanelizerEntityViewBuilder.php
deleted file mode 100644
index 40c734f..0000000
--- a/src/PanelizerEntityViewBuilder.php
+++ /dev/null
@@ -1,412 +0,0 @@
-entityTypeId = $entity_type->id();
- $this->entityType = $entity_type;
- $this->entityTypeManager = $entity_type_manager;
- $this->moduleHandler = $module_handler;
- $this->panelizer = $panelizer;
- $this->panelizerManager = $panelizer_manager;
- $this->panelsManager = $panels_manager;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
- return new static(
- $entity_type,
- $container->get('entity_type.manager'),
- $container->get('module_handler'),
- $container->get('panelizer'),
- $container->get('plugin.manager.panelizer_entity'),
- $container->get('panels.display_manager')
- );
- }
-
- /**
- * Get the Panelizer entity plugin.
- *
- * @return \Drupal\panelizer\Plugin\PanelizerEntityInterface|FALSE
- */
- protected function getPanelizerPlugin() {
- if (!isset($this->panelizerPlugin)) {
- if (!$this->panelizerManager->hasDefinition($this->entityTypeId)) {
- $this->panelizerPlugin = FALSE;
- }
- else {
- $this->panelizerPlugin = $this->panelizerManager->createInstance($this->entityTypeId, []);
- }
- }
-
- return $this->panelizerPlugin;
- }
-
- /**
- * Check if Panelizer should be used for building this display.
- *
- * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display
- * The display we're building.
- *
- * @return bool
- */
- protected function isPanelizerEnabled(EntityViewDisplayInterface $display) {
- return $display->getThirdPartySetting('panelizer', 'enable', FALSE);
- }
-
- /**
- * Gets the original view builder for this entity.
- *
- * @return \Drupal\Core\Entity\EntityViewBuilderInterface
- *
- * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
- */
- protected function getFallbackViewBuilder() {
- return $this->entityTypeManager->getHandler($this->entityTypeId, 'fallback_view_builder');
- }
-
- /**
- * Get the Panels display out of an the entity view display
- *
- * @param \Drupal\Core\Entity\EntityInterface $entity
- * The entity.
- * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display
- * The display.
- * @param $view_mode
- * The view mode.
- *
- * @return \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant
- * The Panels display.
- */
- protected function getPanelsDisplay(EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
- return $this->panelizer->getPanelsDisplay($entity, $view_mode, $display);
- }
-
- /**
- * Returns the display objects used to render a set of entities.
- *
- * Wraps EntityViewDisplay::collectRenderDisplays() so we can mock it in
- * tests.
- *
- * @param \Drupal\Core\Entity\FieldableEntityInterface[] $entities
- * The entities being rendered. They should all be of the same entity type.
- * @param string $view_mode
- * The view mode being rendered.
- *
- * @return \Drupal\Core\Entity\Display\EntityViewDisplayInterface[]
- * The display objects to use to render the entities, keyed by entity
- * bundle.
- *
- * @see EntityViewDisplay::collectRenderDisplays()
- */
- protected function collectRenderDisplays($entities, $view_mode) {
- return EntityViewDisplay::collectRenderDisplays($entities, $view_mode);
- }
-
- /**
- * Returns the entity context.
- *
- * Wraps creating new Context objects to avoid typed data in tests.
- *
- * @param \Drupal\Core\Entity\EntityInterface $entity
- * The entity.
- *
- * @return \Drupal\Core\Plugin\Context\Context
- * The context.
- */
- protected function getEntityContext(EntityInterface $entity) {
- return new AutomaticContext(new ContextDefinition('entity:' . $this->entityTypeId, NULL, TRUE), $entity);
- }
-
- /*
- * Methods from EntityViewBuilderInterface.
- */
-
- /**
- * {@inheritdoc}
- */
- public function buildComponents(array &$build, array $entities, array $displays, $view_mode) {
- $fallback_view_builder = $this->getFallbackViewBuilder();
-
- $panelized_entities = [];
- $fallback_entities = [];
- /**
- * @var string $id
- * @var \Drupal\Core\Entity\EntityInterface $entity
- */
- foreach ($entities as $id => $entity) {
- $display = $displays[$entity->bundle()];
- if ($this->isPanelizerEnabled($display)) {
- $panelized_entities[$id] = $entity;
- }
- else {
- $fallback_entities[$id] = $entity;
- }
- }
-
- // Handle all the fallback entities first!
- if (!empty($fallback_entities)) {
- $fallback_view_builder->buildComponents($build, $fallback_entities, $displays, $view_mode);
- }
-
- // Handle the panelized entities.
- if (!empty($panelized_entities)) {
- $this->moduleHandler
- ->invokeAll('entity_prepare_view', [
- $this->entityTypeId,
- $panelized_entities,
- $displays,
- $view_mode
- ]);
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
- // Trigger hook_panelizer_pre_view_builder_alter().
- $this->moduleHandler->alter('panelizer_pre_view_builder', $view_mode, $entity, $langcode);
-
- $displays = $this->collectRenderDisplays([$entity], $view_mode);
- $display = $displays[$entity->bundle()];
-
- if (!$this->isPanelizerEnabled($display)) {
- return $this->getFallbackViewBuilder()->view($entity, $view_mode, $langcode);
- }
-
- $build = $this->buildMultiplePanelized([$entity->id() => $entity], $displays, $view_mode, $langcode);
- return $build[$entity->id()];
- }
-
- /**
- * {@inheritdoc}
- */
- public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL) {
- $displays = $this->collectRenderDisplays($entities, $view_mode);
-
- $panelized_entities = [];
- $fallback_entities = [];
- foreach ($entities as $id => $entity) {
- $display = $displays[$entity->bundle()];
- if ($this->isPanelizerEnabled($display)) {
- $panelized_entities[$id] = $entity;
- }
- else {
- $fallback_entities[$id] = $entity;
- }
- }
-
- $result = [];
- if (!empty($fallback_entities)) {
- $result += $this->getFallbackViewBuilder()->viewMultiple($fallback_entities, $view_mode, $langcode);
- }
- if (!empty($panelized_entities)) {
- $result += $this->buildMultiplePanelized($panelized_entities, $displays, $view_mode, $langcode);
- }
-
- return $result;
- }
-
- /**
- * {@inheritdoc}
- */
- public function resetCache(array $entities = NULL) {
- $this->getFallbackViewBuilder()->resetCache($entities);
- }
-
- /**
- * {@inheritdoc}
- */
- public function viewField(FieldItemListInterface $items, $display_options = []) {
- return $this->getFallbackViewBuilder()->viewfield($items, $display_options);
- }
-
- /**
- * {@inheritdoc}
- */
- public function viewFieldItem(FieldItemInterface $item, $display = []) {
- return $this->getFallbackViewBuilder()->viewFieldItem($item, $display);
- }
-
- /**
- * {@inheritdoc}
- */
- public function getCacheTags() {
- return $this->getFallbackViewBuilder()->getCacheTags();
- }
-
- /*
- * Methods for actually rendering the Panelized entities.
- */
-
- /**
- * Build the render array for a list of panelized entities.
- *
- * @param \Drupal\Core\Entity\EntityInterface[] $entities
- * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface[] $displays
- * @param string $view_mode
- * @param string|NULL $langcode
- *
- * @return array
- */
- protected function buildMultiplePanelized(array $entities, array $displays, $view_mode, $langcode) {
- $build = [];
-
- foreach ($entities as $id => $entity) {
- $panels_display = $this->panelizer->getPanelsDisplay($entity, $view_mode, $displays[$entity->bundle()]);
- $settings = $this->panelizer->getPanelizerSettings($entity->getEntityTypeId(), $entity->bundle(), $view_mode, $displays[$entity->bundle()]);
- $panels_display->setContexts($this->panelizer->getDisplayStaticContexts($settings['default'], $entity->getEntityTypeId(), $entity->bundle(), $view_mode, $displays[$entity->bundle()]));
- $build[$id] = $this->buildPanelized($entity, $panels_display, $view_mode, $langcode);
-
- // Allow modules to modify the render array.
- $alter_types = [
- "{$this->entityTypeId}_view",
- 'entity_view',
- ];
- $this->moduleHandler->alter($alter_types, $build[$id], $entity, $displays[$entity->bundle()]);
- }
-
- return $build;
- }
-
- /**
- * Build the render array for a single panelized entity.
- *
- * @param \Drupal\Core\Entity\EntityInterface $entity
- * @param \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $panels_display
- * @param string $view_mode
- * @param string $langcode
- *
- * @return array
- */
- protected function buildPanelized(EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode, $langcode) {
- $contexts = $panels_display->getContexts();
- $contexts['@panelizer.entity_context:entity'] = $this->getEntityContext($entity);
- $panels_display->setContexts($contexts);
-
- $build = [
- '#theme' => [
- 'panelizer_view_mode__' . $this->entityTypeId . '__' . $entity->id(),
- 'panelizer_view_mode__' . $this->entityTypeId . '__' . $entity->bundle(),
- 'panelizer_view_mode__' . $this->entityTypeId,
- 'panelizer_view_mode',
- ],
- '#panelizer_plugin' => $this->getPanelizerPlugin(),
- '#panels_display' => $panels_display,
- '#entity' => $entity,
- '#view_mode' => $view_mode,
- '#langcode' => $langcode,
- 'content' => $panels_display->build(),
- ];
-
- if (isset($build['content']['#title'])) {
- $build['#title'] = $build['content']['#title'];
- }
-
- // @todo: I'm sure more is necessary to get the cache contexts right...
- $entity_metadata = CacheableMetadata::createFromObject($entity);
- CacheableMetadata::createFromObject($panels_display)->merge($entity_metadata)->applyTo($build);
-
- $this->getPanelizerPlugin()->alterBuild($build, $entity, $panels_display, $view_mode);
-
- return $build;
- }
-
-}
diff --git a/src/PanelizerInterface.php b/src/PanelizerInterface.php
deleted file mode 100644
index 76a472c..0000000
--- a/src/PanelizerInterface.php
+++ /dev/null
@@ -1,243 +0,0 @@
-panelizerEntityManager = $panelizer_entity_manager;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container, $base_plugin_id) {
- return new static(
- $container->get('plugin.manager.panelizer_entity')
- );
- }
-
- /**
- * {@inheritdoc}
- */
- public function getDerivativeDefinitions($base_plugin_definition) {
- foreach ($this->panelizerEntityManager->getDefinitions() as $plugin_id => $definition) {
- $this->derivatives["$plugin_id"] = $base_plugin_definition;
- $this->derivatives["$plugin_id"]['appears_on'] = [
- "entity.entity_view_display.$plugin_id.default",
- "entity.entity_view_display.$plugin_id.view_mode"
- ];
- }
- return parent::getDerivativeDefinitions($base_plugin_definition);
- }
-
-}
diff --git a/src/Plugin/Field/FieldFormatter/PanelizerFormatter.php b/src/Plugin/Field/FieldFormatter/PanelizerFormatter.php
deleted file mode 100644
index 7eb3666..0000000
--- a/src/Plugin/Field/FieldFormatter/PanelizerFormatter.php
+++ /dev/null
@@ -1,61 +0,0 @@
- $item) {
- $elements[$delta] = [
- '#type' => 'item',
- '#title' => $item->view_mode,
- '#markup' => $this->viewValue($item),
- ];
- }
-
- return $elements;
- }
-
- /**
- * Generate the output appropriate for one field item.
- *
- * @param \Drupal\Core\Field\FieldItemInterface $item
- * One field item.
- *
- * @return string
- * The textual output generated.
- */
- protected function viewValue(FieldItemInterface $item) {
- $description = '';
- if (!empty($item->default)) {
- $description = $this->t('Using default called "@default"', ['@default' => $item->default]);
- }
- else {
- $description = $this->t('Custom');
- }
- return $description;
- }
-
-}
diff --git a/src/Plugin/Field/FieldType/LayoutSettingsItem.php b/src/Plugin/Field/FieldType/LayoutSettingsItem.php
new file mode 100644
index 0000000..8987e72
--- /dev/null
+++ b/src/Plugin/Field/FieldType/LayoutSettingsItem.php
@@ -0,0 +1,73 @@
+ [
+ 'settings' => [
+ 'type' => 'blob',
+ 'size' => 'normal',
+ 'serialize' => TRUE,
+ ],
+ ],
+ ];
+
+ return $schema;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
+ $properties['settings'] = DataDefinition::create('map')
+ ->setLabel(new TranslatableMarkup('Layout Settings'))
+ ->setRequired(FALSE);
+
+ return $properties;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
+ $values['settings'] = [];
+ return $values;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function isEmpty() {
+ return empty($this->settings);
+ }
+}
diff --git a/src/Plugin/Field/FieldType/PanelizerFieldType.php b/src/Plugin/Field/FieldType/PanelizerFieldType.php
deleted file mode 100644
index 8f56c1b..0000000
--- a/src/Plugin/Field/FieldType/PanelizerFieldType.php
+++ /dev/null
@@ -1,143 +0,0 @@
-setLabel(new TranslatableMarkup('View mode'))
- ->setSetting('case_sensitive', FALSE)
- ->setRequired(TRUE);
- $properties['default'] = DataDefinition::create('string')
- ->setLabel(new TranslatableMarkup('Default name'))
- ->setSetting('case_sensitive', FALSE)
- ->setRequired(FALSE);
- $properties['panels_display'] = MapDataDefinition::create('map')
- ->setLabel(new TranslatableMarkup('Panels display'))
- ->setRequired(FALSE);
-
- return $properties;
- }
-
- /**
- * @inheritDoc
- */
- public static function mainPropertyName() {
- return 'panels_display';
- }
-
- /**
- * {@inheritdoc}
- */
- public static function schema(FieldStorageDefinitionInterface $field_definition) {
- $schema = [
- 'columns' => [
- 'view_mode' => [
- 'type' => 'varchar',
- 'length' => '255',
- 'binary' => FALSE,
- ],
- 'default' => [
- 'type' => 'varchar',
- 'length' => '255',
- 'binary' => FALSE,
- ],
- 'panels_display' => [
- 'type' => 'blob',
- 'size' => 'normal',
- 'serialize' => TRUE,
- ],
- ],
- 'indexes' => [
- 'default' => ['default'],
- ]
- ];
-
- return $schema;
- }
-
- /**
- * Returns the Panels display plugin manager.
- *
- * @return \Drupal\panels\PanelsDisplayManagerInterface
- */
- protected static function getPanelsDisplayManager() {
- return \Drupal::service('panels.display_manager');
- }
-
- /**
- * {@inheritdoc}
- */
- public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
- $panels_manager = static::getPanelsDisplayManager();
- $sample_display = $panels_manager->createDisplay();
-
- $values['view_mode'] = 'default';
- $values['default'] = NULL;
- $values['panels_display'] = $panels_manager->exportDisplay($sample_display);
- return $values;
- }
-
- /**
- * {@inheritdoc}
- */
- public function isEmpty() {
- $panels_display = $this->get('panels_display')->getValue();
- $default = $this->get('default')->getValue();
- return empty($panels_display) && empty($default);
- }
-
- /**
- * {@inheritdoc}
- */
- public function postSave($update) {
- $panels_manager = $this->getPanelsDisplayManager();
- $panels_display_config = $this->get('panels_display')->getValue();
-
- // If our field has custom panelizer display config data.
- if (!empty($panels_display_config) && is_array($panels_display_config)) {
- $panels_display = $panels_manager->importDisplay($panels_display_config, FALSE);
- }
- if (!empty($panels_display)) {
- // Set the storage id to include the current revision id.
- $entity = $this->getEntity();
- $storage_id_parts = [
- $entity->getEntityTypeId(),
- $entity->id(),
- $this->get('view_mode')->getValue()
- ];
- if ($entity instanceof RevisionableInterface && $entity->getEntityType()->isRevisionable()) {
- $storage_id_parts[] = $entity->getRevisionId();
- }
- $panels_display->setStorage('panelizer_field', implode(':', $storage_id_parts));
- $this->set('panels_display', $panels_manager->exportDisplay($panels_display));
-
- return TRUE;
- }
- }
-
-}
diff --git a/src/Plugin/Field/FieldWidget/PanelizerWidget.php b/src/Plugin/Field/FieldWidget/PanelizerWidget.php
deleted file mode 100644
index 1695b83..0000000
--- a/src/Plugin/Field/FieldWidget/PanelizerWidget.php
+++ /dev/null
@@ -1,146 +0,0 @@
-getEntity();
- $entity_type_id = $entity->getEntityTypeId();
- $entity_view_modes = $this->getEntityDisplayRepository()->getViewModeOptionsByBundle($entity_type_id, $entity->bundle());
-
- // Get the current values from the entity.
- $values = [];
- /** @var \Drupal\Core\Field\FieldItemInterface $item */
- foreach ($items as $item) {
- $values[$item->view_mode] = [
- 'default' => $item->default,
- 'panels_display' => $item->panels_display,
- ];
- }
-
- // If any view modes are missing, then set the default.
- $displays = [];
- foreach ($entity_view_modes as $view_mode => $view_mode_info) {
- $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
- $displays[$view_mode] = $display->getThirdPartySetting('panelizer', 'displays', []);
- // If we don't have a value, or the default is __bundle_default__ and our
- // panels_display is empty, set the default to __bundle_default__.
- if (!isset($values[$view_mode]) || ($values[$view_mode]['default'] == '__bundle_default__' && empty($values[$view_mode]['panels_display']))) {
- if ($display->getThirdPartySetting('panelizer', 'enable', FALSE)) {
- $values[$view_mode] = [
- 'default' => '__bundle_default__',
- 'panels_display' => [],
- ];
- }
- }
- }
-
- // Add elements to the form for each view mode.
- $delta = 0;
- foreach ($values as $view_mode => $value) {
- $element[$delta]['view_mode'] = [
- '#type' => 'value',
- '#value' => $view_mode,
- ];
-
- $settings = $this->getPanelizer()->getPanelizerSettings($entity_type_id, $entity->bundle(), $view_mode);
- if (!empty($settings['allow'])) {
- // We default to this option when the user hasn't previous interacted
- // with the field.
- $options = [
- '__bundle_default__' => $this->t('Current default display'),
- ];
- foreach ($displays[$view_mode] as $machine_name => $panels_display) {
- $options[$machine_name] = $panels_display['label'];
- }
- $element[$delta]['default'] = [
- '#title' => $entity_view_modes[$view_mode],
- '#type' => 'select',
- '#options' => $options,
- '#default_value' => $value['default'],
- ];
- // If we have a value in panels_display, prevent the user from
- // interacting with the widget for the view modes that are overridden.
- if (!empty($value['panels_display'])) {
- $element[$delta]['default']['#disabled'] = TRUE;
- $element[$delta]['default']['#options'][$value['default']] = $this->t('Custom Override');
- }
- }
- else {
- $element[$delta]['default'] = [
- '#type' => 'value',
- '#value' => $value['default'],
- ];
- }
-
- $element[$delta]['panels_display'] = [
- '#type' => 'value',
- '#value' => $value['panels_display'],
- ];
-
- $delta++;
- }
-
- return $element;
- }
-
-}
diff --git a/src/Plugin/PanelizerEntity/PanelizerNode.php b/src/Plugin/PanelizerEntity/PanelizerNode.php
deleted file mode 100644
index aeec6f9..0000000
--- a/src/Plugin/PanelizerEntity/PanelizerNode.php
+++ /dev/null
@@ -1,81 +0,0 @@
-setPageTitle('[node:title]');
-
- // Remove the 'title' block because it's covered already.
- foreach ($panels_display->getRegionAssignments() as $region => $blocks) {
- /** @var \Drupal\Core\Block\BlockPluginInterface[] $blocks */
- foreach ($blocks as $block_id => $block) {
- if ($block->getPluginId() == 'entity_field:node:title') {
- $panels_display->removeBlock($block_id);
- }
- }
- }
-
- if ($display->getComponent('links')) {
- // @todo: add block for node links.
- }
-
- if ($display->getComponent('langcode')) {
- // @todo: add block for node language.
- }
-
- return $panels_display;
- }
-
- /**
- * {@inheritdoc}
- */
- public function alterBuild(array &$build, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {
- /** @var $entity \Drupal\node\Entity\Node */
- parent::alterBuild($build, $entity, $panels_display, $view_mode);
-
- if ($entity->id()) {
- $build['#contextual_links']['node'] = [
- 'route_parameters' => ['node' => $entity->id()],
- 'metadata' => ['changed' => $entity->getChangedTime()],
- ];
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function preprocessViewMode(array &$variables, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {
- parent::preprocessViewMode($variables, $entity, $panels_display, $view_mode);
-
- /** @var \Drupal\node\NodeInterface $node */
- $node = $entity;
-
- // Add node specific CSS classes.
- if ($node->isPromoted()) {
- $variables['attributes']['class'][] = 'node--promoted';
- }
- if ($node->isSticky()) {
- $variables['attributes']['class'][] = 'node--sticky';
- }
- if (!$node->isPublished()) {
- $variables['attributes']['class'][] = 'node--unpublished';
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/Plugin/PanelizerEntity/PanelizerTerm.php b/src/Plugin/PanelizerEntity/PanelizerTerm.php
deleted file mode 100644
index a78a7d3..0000000
--- a/src/Plugin/PanelizerEntity/PanelizerTerm.php
+++ /dev/null
@@ -1,52 +0,0 @@
-setPageTitle('[term:name]');
-
- // Remove the 'name' block because it's covered already.
- foreach ($panels_display->getRegionAssignments() as $region => $blocks) {
- /** @var \Drupal\Core\Block\BlockPluginInterface[] $blocks */
- foreach ($blocks as $block_id => $block) {
- if ($block->getPluginId() == 'entity_field:taxonomy_term:name') {
- $panels_display->removeBlock($block_id);
- }
- }
- }
-
- return $panels_display;
- }
-
- /**
- * {@inheritdoc}
- */
- public function alterBuild(array &$build, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {
- /** @var $entity \Drupal\taxonomy\Entity\Term */
- parent::alterBuild($build, $entity, $panels_display, $view_mode);
-
- if ($entity->id()) {
- $build['#contextual_links']['taxonomy_term'] = [
- 'route_parameters' => ['taxonomy_term' => $entity->id()],
- 'metadata' => ['changed' => $entity->getChangedTime()],
- ];
- }
- }
-
-}
diff --git a/src/Plugin/PanelizerEntity/PanelizerUser.php b/src/Plugin/PanelizerEntity/PanelizerUser.php
deleted file mode 100644
index c2f84f2..0000000
--- a/src/Plugin/PanelizerEntity/PanelizerUser.php
+++ /dev/null
@@ -1,76 +0,0 @@
-setPageTitle('[user:name]');
-
- // Remove the 'name' block because it's covered already.
- foreach ($panels_display->getRegionAssignments() as $region => $blocks) {
- /** @var \Drupal\Core\Block\BlockPluginInterface[] $blocks */
- foreach ($blocks as $block_id => $block) {
- if ($block->getPluginId() == 'entity_field:user:name') {
- $panels_display->removeBlock($block_id);
- }
- }
- }
-
- if ($display->getComponent('member_for')) {
- // @todo: add block for 'Member for'.
- }
-
- return $panels_display;
- }
-
- /**
- * {@inheritdoc}
- */
- public function alterBuild(array &$build, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {
- /** @var $entity \Drupal\user\Entity\User */
- parent::alterBuild($build, $entity, $panels_display, $view_mode);
-
- if ($entity->id()) {
- $build['#contextual_links']['user'] = [
- 'route_parameters' => ['user' => $entity->id()],
- 'metadata' => ['changed' => $entity->getChangedTime()],
- ];
- }
-
- // This function adds a default alt tag to the user_picture field to
- // maintain accessibility.
- if (user_picture_enabled() && !empty($build['content']['content'])) {
- foreach (Element::children($build['content']['content']) as $key) {
- if (isset($build['content']['content'][$key]['content']['field'])) {
- foreach (Element::children($build['content']['content'][$key]['content']['field']) as $field_key) {
- if ($build['content']['content'][$key]['content']['field']['#field_name'] == 'user_picture') {
- if (empty($build['content']['content'][$key]['content']['field'][$field_key]['#item_attributes'])) {
- $build['content']['content'][$key]['content']['field'][$field_key]['#item_attributes'] = [
- 'alt' => \Drupal::translation()
- ->translate('Profile picture for user @username', ['@username' => $entity->getUsername()])
- ];
- }
- }
- }
- }
- }
- }
- }
-
-}
diff --git a/src/Plugin/PanelizerEntityBase.php b/src/Plugin/PanelizerEntityBase.php
deleted file mode 100644
index 30a8b53..0000000
--- a/src/Plugin/PanelizerEntityBase.php
+++ /dev/null
@@ -1,133 +0,0 @@
-panelsManager = $panels_manager;
- $this->entityFieldManager = $entity_field_manager;
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
- return new static(
- $configuration,
- $plugin_id,
- $plugin_definition,
- $container->get('panels.display_manager'),
- $container->get('entity_field.manager')
- );
- }
-
- /**
- * {@inheritdoc}
- */
- public function getDefaultDisplay(EntityViewDisplayInterface $display, $bundle, $view_mode) {
- $panels_display = $this->panelsManager->createDisplay();
-
- $panels_display->setConfiguration(['label' => $this->t('Default')] + $panels_display->getConfiguration());
- $panels_display->setLayout('layout_onecol');
- // @todo: For now we always use the IPE, but we should support not using the ipe.
- $panels_display->setBuilder('ipe');
- $panels_display->setPattern('panelizer');
-
- // Add all the visible fields to the Panel.
- $entity_type_id = $this->getPluginId();
- /**
- * @var string $field_name
- * @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition
- */
- foreach ($this->entityFieldManager->getFieldDefinitions($entity_type_id, $bundle) as $field_name => $field_definition) {
- // Skip the Panelizer field.
- if ($field_definition->getType() == 'panelizer') {
- continue;
- }
-
- if ($component = $display->getComponent($field_name)) {
- $weight = $component['weight'];
- unset($component['weight']);
-
- $panels_display->addBlock([
- 'id' => 'entity_field:' . $entity_type_id . ':' . $field_name,
- 'label' => $field_definition->getLabel(),
- 'provider' => 'ctools_block',
- 'label_display' => '0',
- 'formatter' => $component,
- 'context_mapping' => [
- 'entity' => '@panelizer.entity_context:entity',
- ],
- 'region' => 'content',
- 'weight' => $weight,
- ]);
- }
- }
-
- return $panels_display;
- }
-
- /**
- * {@inheritdoc}
- */
- public function alterBuild(array &$build, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {
- // By default, do nothing!
- }
-
- /**
- * {@inheritdoc}
- */
- public function preprocessViewMode(array &$variables, EntityInterface $entity, PanelsDisplayVariant $panels_display, $view_mode) {
- $entity_type_id = $this->getPluginId();
-
- // Add some default classes.
- $variables['attributes']['class'][] = $entity_type_id;
- $variables['attributes']['class'][] = $entity_type_id . '--type-' . $entity->bundle();
- $variables['attributes']['class'][] = $entity_type_id . '--view-mode-' . $view_mode;
- $variables['attributes']['class'][] = 'clearfix';
-
- // Don't render the title in the template
- if ($view_mode == 'full') {
- $variables['title'] = '';
- }
- }
-
-}
diff --git a/src/Plugin/PanelizerEntityInterface.php b/src/Plugin/PanelizerEntityInterface.php
deleted file mode 100644
index 189e2db..0000000
--- a/src/Plugin/PanelizerEntityInterface.php
+++ /dev/null
@@ -1,70 +0,0 @@
-alterInfo('panelizer_entity_info');
- $this->setCacheBackend($cache_backend, 'panelizer_entity_plugins');
- }
-
-}
diff --git a/src/Plugin/PanelizerEntityManagerInterface.php b/src/Plugin/PanelizerEntityManagerInterface.php
deleted file mode 100644
index 4b6d471..0000000
--- a/src/Plugin/PanelizerEntityManagerInterface.php
+++ /dev/null
@@ -1,13 +0,0 @@
-t('Entity being panelized'));
- $contexts['@panelizer.entity_context:entity'] = new AutomaticContext($entity_definition);
- $user_definition = new ContextDefinition("entity:user", $this->t('Current user'));
- $contexts['current_user'] = new Context($user_definition);
- return $contexts + parent::getDefaultContexts($tempstore, $tempstore_id, $machine_name);
- }
-
-}
diff --git a/src/Plugin/PanelsStorage/PanelizerDefaultPanelsStorage.php b/src/Plugin/PanelsStorage/PanelizerDefaultPanelsStorage.php
deleted file mode 100644
index 738b98d..0000000
--- a/src/Plugin/PanelsStorage/PanelizerDefaultPanelsStorage.php
+++ /dev/null
@@ -1,192 +0,0 @@
-entityTypeManager = $entity_type_manager;
- $this->panelizer = $panelizer;
- parent::__construct($configuration, $plugin_id, $plugin_definition);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
- return new static(
- $configuration,
- $plugin_id,
- $plugin_definition,
- $container->get('entity_type.manager'),
- $container->get('panelizer')
- );
- }
-
- /**
- * Converts the storage id into its component parts.
- *
- * @param string $id
- * The storage id. There are two formats that can potentially be used:
- * - The first is the normal format that we actually store:
- * "entity_type_id:bundle:view_mode:name"
- * - The second is a special internal format we use in the IPE so we can
- * correctly set context:
- * "*entity_type_id:entity_id:view_mode:name"
- *
- * @return array
- * An array with 4 or 5 items:
- * - Entity type id: string
- * - Bundle name: string
- * - View mode: string
- * - Default name: string
- * - Entity: \Drupal\Core\Entity\EntityInterface|NULL
- *
- * @throws \Drupal\panelizer\Exception\PanelizerException
- */
- protected function parseId($id) {
- list ($entity_type_id, $part_two, $view_mode, $name) = explode(':', $id);
-
- if (strpos($entity_type_id, '*') === 0) {
- $entity_type_id = substr($entity_type_id, 1);
- $storage = $this->entityTypeManager->getStorage($entity_type_id);
- if ($entity = $storage->load($part_two)) {
- $bundle = $entity->bundle();
- }
- else {
- throw new PanelizerException("Unable to load $entity_type_id with id $part_two");
- }
- }
- else {
- $entity = NULL;
- $bundle = $part_two;
- }
-
- return [$entity_type_id, $bundle, $view_mode, $name, $entity];
- }
-
- /**
- * Returns the entity context.
- *
- * Wraps creating new Context objects to avoid typed data in tests.
- *
- * @param string $entity_type_id
- * The entity type id.
- * @param \Drupal\Core\Entity\EntityInterface|NULL $entity
- * The entity.
- *
- * @return \Drupal\Core\Plugin\Context\Context[]
- * The available contexts.
- */
- protected function getEntityContext($entity_type_id, EntityInterface $entity = NULL) {
- $contexts = [];
- // Set a placeholder context so that the calling code knows that we need
- // an entity context. If we have the value available, then we actually set
- // the context value.
- $contexts['@panelizer.entity_context:entity'] = new AutomaticContext(new ContextDefinition('entity:' . $entity_type_id, NULL, TRUE), $entity);
- return $contexts;
- }
-
-
-
- /**
- * {@inheritdoc}
- */
- public function load($id) {
- try {
- list ($entity_type_id, $bundle, $view_mode, $name, $entity) = $this->parseId($id);
- if ($panels_display = $this->panelizer->getDefaultPanelsDisplay($name, $entity_type_id, $bundle, $view_mode)) {
- $contexts = $this->getEntityContext($entity_type_id, $entity);
- $contexts = $contexts + $this->panelizer->getDisplayStaticContexts($name, $entity_type_id, $bundle, $view_mode);
- $panels_display->setContexts($contexts);
- return $panels_display;
- }
- }
- catch (PanelizerException $e) {
- // Do nothing to fallback on returning NULL.
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function save(PanelsDisplayVariant $panels_display) {
- $id = $panels_display->getStorageId();
- try {
- list ($entity_type_id, $bundle, $view_mode, $name) = $this->parseId($id);
- $this->panelizer->setDefaultPanelsDisplay($name, $entity_type_id, $bundle, $view_mode, $panels_display);
- }
- catch (PanelizerException $e) {
- throw new \Exception("Couldn't find Panelizer default to store Panels display");
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function access($id, $op, AccountInterface $account) {
- try {
- list ($entity_type_id, $bundle, $view_mode, $name) = $this->parseId($id);
- }
- catch (PanelizerException $e) {
- return AccessResult::forbidden();
- }
-
- if ($panels_display = $this->panelizer->getDefaultPanelsDisplay($name, $entity_type_id, $bundle, $view_mode)) {
- if ($op == 'change layout') {
- if ($this->panelizer->hasDefaultPermission('change layout', $entity_type_id, $bundle, $view_mode, $name, $account)) {
- return AccessResult::allowed();
- }
- }
- else if ($op == 'read' || $this->panelizer->hasDefaultPermission('change content', $entity_type_id, $bundle, $view_mode, $name, $account)) {
- return AccessResult::allowed();
- }
- }
-
- return AccessResult::forbidden();
- }
-
-}
\ No newline at end of file
diff --git a/src/Plugin/PanelsStorage/PanelizerFieldPanelsStorage.php b/src/Plugin/PanelsStorage/PanelizerFieldPanelsStorage.php
deleted file mode 100644
index ca946f8..0000000
--- a/src/Plugin/PanelsStorage/PanelizerFieldPanelsStorage.php
+++ /dev/null
@@ -1,196 +0,0 @@
-entityTypeManager = $entity_type_manager;
- $this->panelizer = $panelizer;
- parent::__construct($configuration, $plugin_id, $plugin_definition);
- }
-
- /**
- * {@inheritdoc}
- */
- public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
- return new static(
- $configuration,
- $plugin_id,
- $plugin_definition,
- $container->get('entity_type.manager'),
- $container->get('panelizer')
- );
- }
-
- /**
- * Gets the underlying entity from storage.
- *
- * @param $id
- * The storage service id.
- *
- * @return \Drupal\Core\Entity\EntityInterface|NULL
- */
- protected function loadEntity($id) {
- list ($entity_type, $id, , $revision_id) = array_pad(explode(':', $id), 4, NULL);
-
- $storage = $this->entityTypeManager->getStorage($entity_type);
- if ($revision_id) {
- $entity = $storage->loadRevision($revision_id);
- }
- else {
- $entity = $storage->load($id);
- }
-
- return $entity;
- }
-
- /**
- * Returns the entity context.
- *
- * Wraps creating new Context objects to avoid typed data in tests.
- *
- * @param string $entity_type_id
- * The entity type id.
- * @param \Drupal\Core\Entity\EntityInterface $entity
- * The entity.
- *
- * @return \Drupal\Core\Plugin\Context\Context
- * The context.
- */
- protected function getEntityContext($entity_type_id, EntityInterface $entity) {
- return new AutomaticContext(new ContextDefinition('entity:' . $entity_type_id, NULL, TRUE), $entity);
- }
-
- /**
- * {@inheritdoc}
- */
- public function load($id) {
- if ($entity = $this->loadEntity($id)) {
- list ($entity_type_id, , $view_mode) = explode(':', $id);
- if ($panels_display = $this->panelizer->getPanelsDisplay($entity, $view_mode)) {
- // Set the entity as a context on the Panels display.
- $contexts = [
- '@panelizer.entity_context:entity' => $this->getEntityContext($entity_type_id, $entity),
- ];
- $panels_display->setContexts($contexts);
- return $panels_display;
- }
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function save(PanelsDisplayVariant $panels_display) {
- $id = $panels_display->getStorageId();
- if ($entity = $this->loadEntity($id)) {
- list (,, $view_mode) = explode(':', $id);
- // If we're dealing with an entity that has a documented default, we
- // don't want to lose that information when we save our customizations.
- // This enables us to revert to the correct default at a later date.
- if ($entity instanceof FieldableEntityInterface) {
- $default = NULL;
- if ($entity->hasField('panelizer') && $entity->panelizer->first()) {
- foreach ($entity->panelizer as $item) {
- if ($item->view_mode == $view_mode) {
- $default = $item->default;
- break;
- }
- }
- }
- try {
- $this->panelizer->setPanelsDisplay($entity, $view_mode, $default, $panels_display);
- }
- catch (PanelizerException $e) {
- // Translate to expected exception type.
- throw new \Exception($e->getMessage());
- }
- }
- }
- else {
- throw new \Exception("Couldn't find entity to store Panels display on");
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function access($id, $op, AccountInterface $account) {
- if ($entity = $this->loadEntity($id)) {
- $access = AccessResult::neutral()
- ->addCacheableDependency($account);
-
- // We do not support "create", as this method's interface dictates,
- // because we work with existing entities here.
- $entity_operations = [
- 'read' => 'view',
- 'update' => 'update',
- 'delete'=> 'delete',
- 'change layout' => 'update',
- ];
- // Do not add entity cacheability metadata to the forbidden result,
- // because it depends on the Panels operation, and not on the entity.
- $access->orIf(isset($entity_operations[$op]) ? $entity->access($entity_operations[$op], $account, TRUE) : AccessResult::forbidden());
-
- if (!$access->isForbidden() && $entity instanceof FieldableEntityInterface) {
- list (,, $view_mode) = explode(':', $id);
- if ($op == 'change layout') {
- if ($this->panelizer->hasEntityPermission('change layout', $entity, $view_mode, $account)) {
- return $access->orIf(AccessResult::allowed());
- }
- }
- else if ($op == 'read' || $this->panelizer->hasEntityPermission('change content', $entity, $view_mode, $account)) {
- return $access->orIf(AccessResult::allowed());
- }
- }
- }
-
- return AccessResult::forbidden();
- }
-
-}
diff --git a/src/Plugin/Relationship/ConfigurableRelationshipBase.php b/src/Plugin/Relationship/ConfigurableRelationshipBase.php
new file mode 100644
index 0000000..c2fa38f
--- /dev/null
+++ b/src/Plugin/Relationship/ConfigurableRelationshipBase.php
@@ -0,0 +1,102 @@
+configuration;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setConfiguration(array $configuration) {
+ $this->configuration = $configuration;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function defaultConfiguration() {
+ return [];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function calculateDependencies() {
+ return [];
+ }
+
+ /**
+ * Form constructor.
+ *
+ * Plugin forms are embedded in other forms. In order to know where the plugin
+ * form is located in the parent form, #parents and #array_parents must be
+ * known, but these are not available during the initial build phase. In order
+ * to have these properties available when building the plugin form's
+ * elements, let this method return a form element that has a #process
+ * callback and build the rest of the form in the callback. By the time the
+ * callback is executed, the element's #parents and #array_parents properties
+ * will have been set by the form API. For more documentation on #parents and
+ * #array_parents, see \Drupal\Core\Render\Element\FormElement.
+ *
+ * @param array $form
+ * An associative array containing the initial structure of the plugin form.
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form. Calling code should pass on a subform
+ * state created through
+ * \Drupal\Core\Form\SubformState::createForSubform().
+ *
+ * @return array
+ * The form structure.
+ */
+ public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
+ $form['#tree'] = TRUE;
+
+ $contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
+ $form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts);
+
+ return $form;
+ }
+
+ /**
+ * Form validation handler.
+ *
+ * @param array $form
+ * An associative array containing the structure of the plugin form as built
+ * by static::buildConfigurationForm().
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form. Calling code should pass on a subform
+ * state created through
+ * \Drupal\Core\Form\SubformState::createForSubform().
+ */
+ public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
+ }
+
+ /**
+ * Form submission handler.
+ *
+ * @param array $form
+ * An associative array containing the structure of the plugin form as built
+ * by static::buildConfigurationForm().
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form. Calling code should pass on a subform
+ * state created through
+ * \Drupal\Core\Form\SubformState::createForSubform().
+ */
+ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
+ $this->configuration['context_mapping'] = $form_state->getValues('context_mapping');
+ }
+}
diff --git a/src/Plugin/Relationship/ConfigurableRelationshipInterface.php b/src/Plugin/Relationship/ConfigurableRelationshipInterface.php
new file mode 100644
index 0000000..3dcc097
--- /dev/null
+++ b/src/Plugin/Relationship/ConfigurableRelationshipInterface.php
@@ -0,0 +1,12 @@
+getContextValues(
+ $this->getStaticContextConfiguration()
+ );
+
+ /** @var \Drupal\ctools\Plugin\RelationshipManager $relationship_manager */
+ $relationship_manager = \Drupal::service('plugin.manager.ctools.relationship');
+ /** @var \Drupal\Core\Plugin\Context\ContextHandler $context_handler */
+ $context_handler = \Drupal::service('context.handler');
+
+ foreach ($this->getRelationshipsConfiguration() as $machine_name => $relationship) {
+ /** @var \Drupal\ctools\Plugin\RelationshipInterface $plugin */
+ $plugin = $relationship_manager->createInstance($relationship['plugin'], $relationship['settings'] ?: []);
+ $context_handler->applyContextMapping($plugin, $contexts);
+
+ $contexts[$machine_name] = $plugin->getRelationship();
+ }
+
+ return $contexts;
+ }
+
+ /**
+ * Get the relationships configuration.
+ *
+ * @return array
+ */
+ protected function getRelationshipsConfiguration() {
+ return [];
+ }
+
+ /**
+ * Get the relationships configuration.
+ *
+ * @return array
+ */
+ protected function getStaticContextConfiguration() {
+ return [];
+ }
+}
diff --git a/src/Plugin/SectionStorage/DefaultsSectionStorage.php b/src/Plugin/SectionStorage/DefaultsSectionStorage.php
new file mode 100644
index 0000000..11b4d73
--- /dev/null
+++ b/src/Plugin/SectionStorage/DefaultsSectionStorage.php
@@ -0,0 +1,24 @@
+getThirdPartySetting('panelizer', 'relationships', []);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getStaticContextConfiguration() {
+ return $this->getThirdPartySetting('panelizer', 'static_context', []);
+ }
+}
diff --git a/src/Plugin/SectionStorage/OverridesSectionStorage.php b/src/Plugin/SectionStorage/OverridesSectionStorage.php
new file mode 100644
index 0000000..4446265
--- /dev/null
+++ b/src/Plugin/SectionStorage/OverridesSectionStorage.php
@@ -0,0 +1,120 @@
+getEntity()->get(static::SETTINGS_FIELD_NAME)->settings;
+ $settings[$module][$key] = $value;
+ $this->getEntity()->get(static::SETTINGS_FIELD_NAME)->settings = $settings;
+
+ return $settings;
+ }
+
+ /**
+ * Gets the value of a third-party setting.
+ *
+ * @param string $module
+ * The module providing the third-party setting.
+ * @param string $key
+ * The setting name.
+ * @param mixed $default
+ * The default value
+ *
+ * @return mixed
+ * The value.
+ */
+ public function getThirdPartySetting($module, $key, $default = NULL) {
+ $settings = $this->getEntity()->get(static::SETTINGS_FIELD_NAME)->settings;
+ if (isset($settings[$module][$key])) {
+ return $settings[$module][$key];
+ }
+
+ return $default;
+ }
+
+ /**
+ * Gets all third-party settings of a given module.
+ *
+ * @param string $module
+ * The module providing the third-party settings.
+ *
+ * @return array
+ * An array of key-value pairs.
+ */
+ public function getThirdPartySettings($module) {
+ $settings = $this->getEntity()->get(static::SETTINGS_FIELD_NAME)->settings;
+ if (isset($settings[$module])) {
+ return $settings[$module];
+ }
+
+ return [];
+ }
+
+ /**
+ * Unsets a third-party setting.
+ *
+ * @param string $module
+ * The module providing the third-party setting.
+ * @param string $key
+ * The setting name.
+ *
+ * @return mixed
+ * The value.
+ */
+ public function unsetThirdPartySetting($module, $key) {
+ $settings = $this->getEntity()->get(static::SETTINGS_FIELD_NAME)->settings;
+ $value = $settings[$module][$key];
+ unset($settings[$module][$key]);
+ $this->getEntity()->get(static::SETTINGS_FIELD_NAME)->settings = $settings;
+
+ return $value;
+ }
+
+ /**
+ * Gets the list of third parties that store information.
+ *
+ * @return array
+ * The list of third parties.
+ */
+ public function getThirdPartyProviders() {
+ $settings = $this->getEntity()->get(static::SETTINGS_FIELD_NAME)->settings;
+ return array_keys($settings);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getRelationshipsConfiguration() {
+ return $this->getThirdPartySetting('panelizer', 'relationships', []);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getStaticContextConfiguration() {
+ return $this->getThirdPartySetting('panelizer', 'static_context', []);
+ }
+}
diff --git a/src/Tests/Update/PanelizerLayoutIDUpdateTest.php b/src/Tests/Update/PanelizerLayoutIDUpdateTest.php
deleted file mode 100644
index f08af8e..0000000
--- a/src/Tests/Update/PanelizerLayoutIDUpdateTest.php
+++ /dev/null
@@ -1,41 +0,0 @@
-databaseDumpFiles = [
- __DIR__ . '/../../../tests/fixtures/update/drupal-8.panelizer.minimal.php.gz',
- ];
- }
-
- /**
- * Test updates.
- */
- public function testUpdate() {
- $this->runUpdates();
-
- $this->drupalLogin($this->rootUser);
- $this->drupalGet('admin/structure/types/manage/article/display');
- $this->clickLink('Edit', 1);
- $this->assertResponse(200);
-
- $this->drupalGet('node/1');
- $this->assertResponse(200);
-
- $this->drupalGet('node/2');
- $this->assertResponse(200);
- }
-
-}
diff --git a/src/Wizard/PanelizerAddWizard.php b/src/Wizard/PanelizerAddWizard.php
deleted file mode 100644
index 85513e8..0000000
--- a/src/Wizard/PanelizerAddWizard.php
+++ /dev/null
@@ -1,72 +0,0 @@
-set('machine_name_prefix', "{$entity_type_id}__{$bundle}__{$view_mode_name}");
- }
- $form = parent::buildForm($form, $form_state);
- $cached_values = $form_state->getTemporaryValue('wizard');
- $cached_values['id'] = $this->getMachineName();
- // Some variants like PanelsDisplayVariant need this. Set it to empty.
- $cached_values['access'] = [];
- $form_state->setTemporaryValue('wizard', $cached_values);
- return $form;
- }
-
- /**
- * {@inheritdoc}
- */
- public function submitForm(array &$form, FormStateInterface $form_state) {
- $operations = array_map('strval', [
- $this->getNextOp(),
- $this->t('Update'),
- $this->t('Update and save'),
- $this->t('Save'),
- ]);
-
- if (in_array($form_state->getValue('op'), $operations)) {
- $cached_values = $form_state->getTemporaryValue('wizard');
- if ($form_state->hasValue('label')) {
- $config = $cached_values['plugin']->getConfiguration();
- $config['label'] = $form_state->getValue('label');
- $cached_values['plugin']->setConfiguration($config);
- }
- if ($form_state->hasValue('id')) {
- $cached_values['id'] = $form_state->getValue('id');
- /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $plugin */
- $plugin = $cached_values['plugin'];
- $plugin->setStorage($plugin->getStorageType(), $cached_values['id']);
- }
- }
- parent::submitForm($form, $form_state);
- }
-
- /**
- * {@inheritdoc}
- */
- public function finish(array &$form, FormStateInterface $form_state) {
- parent::finish($form, $form_state);
- $cached_values = $form_state->getTemporaryValue('wizard');
- $form_state->setRedirect('panelizer.wizard.edit', ['machine_name' => $cached_values['id'], 'step' => 'content']);
- }
-
-}
diff --git a/src/Wizard/PanelizerEditWizard.php b/src/Wizard/PanelizerEditWizard.php
deleted file mode 100644
index fd68561..0000000
--- a/src/Wizard/PanelizerEditWizard.php
+++ /dev/null
@@ -1,225 +0,0 @@
-getMachineName();
- list($entity_type, $bundle, $view_mode, $display_id) = explode('__', $this->getMachineName());
- $panelizer = \Drupal::service('panelizer');
- // Load the panels display variant.
- /** @var \Drupal\panelizer\Panelizer $panelizer */
- // @todo this $display_id looks all wrong to me since it's the name and view_mode.
- $variant_plugin = $panelizer->getDefaultPanelsDisplay($display_id, $entity_type, $bundle, $view_mode);
- $cached_values['plugin'] = $variant_plugin;
- $cached_values['label'] = $cached_values['plugin']->getConfiguration()['label'];
-
- $display = $panelizer->getEntityViewDisplay($entity_type, $bundle, $view_mode);
- $config = $display->getThirdPartySetting('panelizer', 'displays', []);
- if (!empty($config[$display_id]['static_context'])) {
- $cached_values['contexts'] = $config[$display_id]['static_context'];
- }
- return $cached_values;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function customizeForm(array $form, FormStateInterface $form_state) {
- // The page actions.
- $form['wizard_actions'] = [
- '#theme' => 'links',
- '#links' => [],
- '#attributes' => [
- 'class' => ['inline'],
- ]
- ];
-
- // The tree of wizard steps.
- $form['wizard_tree'] = [
- '#theme' => ['panelizer_wizard_tree'],
- '#wizard' => $this,
- '#cached_values' => $form_state->getTemporaryValue('wizard'),
- ];
-
- $form['#theme'] = 'panelizer_wizard_form';
- $form['#attached']['library'][] = 'panelizer/wizard_admin';
- $form = parent::customizeForm($form, $form_state);
- return $form;
- }
-
- /**
- * {@inheritdoc}
- */
- protected function actions(FormInterface $form_object, FormStateInterface $form_state) {
- $cached_values = $form_state->getTemporaryValue('wizard');
- $operation = $this->getOperation($cached_values);
-
- $actions = [];
-
- $actions['submit'] = [
- '#type' => 'submit',
- '#value' => $this->t('Update'),
- '#validate' => [
- '::populateCachedValues',
- [$form_object, 'validateForm'],
- ],
- '#submit' => [
- [$form_object, 'submitForm'],
- ],
- ];
-
- $actions['update_and_save'] = [
- '#type' => 'submit',
- '#value' => $this->t('Update and save'),
- '#button_type' => 'primary',
- '#validate' => [
- '::populateCachedValues',
- [$form_object, 'validateForm'],
- ],
- '#submit' => [
- [$form_object, 'submitForm'],
- ],
- ];
-
- $actions['finish'] = [
- '#type' => 'submit',
- '#value' => $this->t('Save'),
- '#validate' => [
- '::populateCachedValues',
- [$form_object, 'validateForm'],
- ],
- '#submit' => [
- [$form_object, 'submitForm'],
- ],
- ];
-
- $actions['cancel'] = [
- '#type' => 'submit',
- '#value' => $this->t('Cancel'),
- '#submit' => [
- '::clearTempstore'
- ],
- ];
-
- // Add any submit or validate functions for the step and the global ones.
- foreach (['submit', 'update_and_save', 'finish'] as $button) {
- if (isset($operation['validate'])) {
- $actions[$button]['#validate'] = array_merge($actions[$button]['#validate'], $operation['validate']);
- }
- $actions[$button]['#validate'][] = '::validateForm';
- if (isset($operation['submit'])) {
- $actions[$button]['#submit'] = array_merge($actions[$button]['#submit'], $operation['submit']);
- }
- $actions[$button]['#submit'][] = '::submitForm';
- }
- $actions['update_and_save']['#submit'][] = '::finish';
- $actions['finish']['#submit'][] = '::finish';
-
- if ($form_state->get('ajax')) {
- $cached_values = $form_state->getTemporaryValue('wizard');
- $ajax_parameters = $this->getNextParameters($cached_values);
- $ajax_parameters['step'] = $this->getStep($cached_values);
- $ajax_url = Url::fromRoute($this->getRouteName(), $ajax_parameters);
- $ajax_options = [
- 'query' => $this->getRequest()->query->all() + [
- FormBuilderInterface::AJAX_FORM_REQUEST => TRUE,
- ],
- ];
- $actions['submit']['#ajax'] = [
- 'callback' => '::ajaxSubmit',
- 'url' => $ajax_url,
- 'options' => $ajax_options,
- ];
- $actions['update_and_save']['#ajax'] = [
- 'callback' => '::ajaxFinish',
- 'url' => $ajax_url,
- 'options' => $ajax_options,
- ];
- $actions['finish']['#ajax'] = [
- 'callback' => '::ajaxFinish',
- 'url' => $ajax_url,
- 'options' => $ajax_options,
- ];
- }
-
- return $actions;
- }
-
- /**
- * {@inheritdoc}
- */
- public function submitForm(array &$form, FormStateInterface $form_state) {
- $operations = array_map('strval', [
- $this->getNextOp(),
- $this->t('Update'),
- $this->t('Update and save'),
- $this->t('Save'),
- ]);
-
- if (in_array($form_state->getValue('op'), $operations)) {
- $cached_values = $form_state->getTemporaryValue('wizard');
- if ($form_state->hasValue('label')) {
- $config = $cached_values['plugin']->getConfiguration();
- $config['label'] = $form_state->getValue('label');
- $cached_values['plugin']->setConfiguration($config);
- }
- if ($form_state->hasValue('id')) {
- $cached_values['id'] = $form_state->getValue('id');
- }
- if (is_null($this->machine_name) && !empty($cached_values['id'])) {
- $this->machine_name = $cached_values['id'];
- }
- $this->getTempstore()->set($this->getMachineName(), $cached_values);
- if (!$form_state->get('ajax')) {
- $form_state->setRedirect($this->getRouteName(), $this->getNextParameters($cached_values));
- }
- }
- }
-
- /**
- * Clears the temporary store.
- *
- * @param array $form
- * @param \Drupal\Core\Form\FormStateInterface $form_state
- */
- public function clearTempstore(array &$form, FormStateInterface $form_state) {
- $this->getTempstore()->delete($this->getMachineName());
- list($entity_type_id, $bundle, $view_mode) = explode('__', $this->getMachineName());
- $bundle_entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id)->getBundleEntityType();
- if ($view_mode == 'default') {
- $route = "entity.entity_view_display.{$entity_type_id}.default";
- $arguments = [
- $bundle_entity_type => $bundle,
- ];
- }
- else {
- $route = "entity.entity_view_display.{$entity_type_id}.view_mode";
- $arguments = [
- $bundle_entity_type => $bundle,
- 'view_mode_name' => $view_mode,
- ];
- }
- $form_state->setRedirect($route, $arguments);
- }
-
-}
diff --git a/src/Wizard/PanelizerWizardBase.php b/src/Wizard/PanelizerWizardBase.php
deleted file mode 100644
index ac446b4..0000000
--- a/src/Wizard/PanelizerWizardBase.php
+++ /dev/null
@@ -1,168 +0,0 @@
-getTemporaryValue('wizard');
- // Get the current form operation.
- $operation = $this->getOperation($cached_values);
- $operations = $this->getOperations($cached_values);
- $default_operation = reset($operations);
-
- // Get the machine name. There are two ways we can get this data.
- $storage = $form_state->getStorage();
- $prefix = isset($storage['machine_name_prefix']) ? $storage['machine_name_prefix'] : $form_state->getTemporaryValue('wizard')['id'];
-
- if ($operation['form'] == $default_operation['form']) {
- // Create id and label form elements.
- $form['name'] = [
- '#type' => 'fieldset',
- '#attributes' => ['class' => ['fieldset-no-legend']],
- '#title' => $this->getWizardLabel(),
- ];
- $form['name']['label'] = [
- '#type' => 'textfield',
- '#title' => $this->getMachineLabel(),
- '#required' => TRUE,
- '#size' => 32,
- '#default_value' => !empty($cached_values['label']) ? $cached_values['label'] : '',
- '#maxlength' => 255,
- '#disabled' => !empty($cached_values['label']),
- ];
- $form['name']['id'] = [
- '#type' => 'machine_name',
- '#maxlength' => 128,
- '#machine_name' => [
- 'source' => ['name', 'label'],
- 'exists' => $this->exists(),
- 'prefix' => $prefix,
- ],
- '#description' => $this->t('A unique machine-readable name for this display. It must only contain lowercase letters, numbers, and underscores.'),
- '#default_value' => !empty($cached_values['id']) ? $cached_values['id'] : '',
- '#disabled' => !empty($cached_values['id']),
- ];
- }
- return $form;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getWizardLabel() {
- return $this->t('Wizard Information');
- }
-
- /**
- * {@inheritdoc}
- */
- public function getMachineLabel() {
- return $this->t('Wizard name');
- }
-
- /**
- * {@inheritdoc}
- */
- public function exists() {
- return '\Drupal\panelizer\Form\PanelizerWizardGeneralForm::validateMachineName';
- }
-
- /**
- * {@inheritdoc}
- */
- public function getOperations($cached_values) {
- $operations = [
- 'general' => [
- 'form' => PanelizerWizardGeneralForm::class,
- 'title' => $this->t('General settings'),
- ],
- 'contexts' => [
- 'form' => PanelizerWizardContextForm::class,
- 'title' => $this->t('Contexts'),
- ],
- ];
-
- // Add any wizard operations from the plugin itself.
- foreach ($cached_values['plugin']->getWizardOperations($cached_values) as $name => $operation) {
- $operations[$name] = $operation;
- }
-
- // Change the class that manages the Content step.
- if (isset($operations['content'])) {
- //$operations['content']['form'] = PanelizerWizardContentForm::class;
- }
-
- return $operations;
- }
-
- public function initValues() {
- $cached_values = parent::initValues();
- $cached_values['access'] = new PanelizerUIAccess();
- if (empty($cached_values['plugin'])) {
- /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $plugin */
- $plugin = \Drupal::service('plugin.manager.display_variant')->createInstance('panels_variant');
- $plugin->setPattern('panelizer');
- $plugin->setBuilder('ipe');
- $plugin->setStorage('panelizer_default', 'TEMPORARY_STORAGE_ID');
- $cached_values['plugin'] = $plugin;
- }
- if (empty($cached_values['contexts'])) {
- $cached_values['contexts'] = [];
- }
- return $cached_values;
- }
-
-
- /**
- * {@inheritdoc}
- */
- public function finish(array &$form, FormStateInterface $form_state) {
- $cached_values = $form_state->getTemporaryValue('wizard');
-
- // Save the panels display mode and its custom settings as third party
- // data of the display mode for this entity+bundle+display.
- /** @var \Drupal\panelizer\Panelizer $panelizer */
- $panelizer = \Drupal::service('panelizer');
- /** @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface $invalidator */
- $invalidator = \Drupal::service('cache_tags.invalidator');
- list($entity_type, $bundle, $view_mode, $display_id) = explode('__', $cached_values['id']);
- $panelizer->setDefaultPanelsDisplay($display_id, $entity_type, $bundle, $view_mode, $cached_values['plugin']);
- $panelizer->setDisplayStaticContexts($display_id, $entity_type, $bundle, $view_mode, $cached_values['contexts']);
-
- parent::finish($form, $form_state);
- $form_state->setRedirect('panelizer.wizard.edit', ['machine_name' => $cached_values['id']]);
- $invalidator->invalidateTags(["panelizer_default:$entity_type:$bundle:$view_mode:$display_id"]);
- }
-
- /**
- * Wraps the context mapper.
- *
- * @return \Drupal\ctools\ContextMapperInterface
- */
- protected function getContextMapper() {
- return \Drupal::service('ctools.context_mapper');
- }
-
- /**
- * {@inheritdoc}
- */
- protected function getContexts($cached_values) {
- return $this->getContextMapper()->getContextValues($cached_values['contexts']);
- }
-
-}
diff --git a/templates/panelizer-view-mode.html.twig b/templates/panelizer-view-mode.html.twig
deleted file mode 100644
index 415b691..0000000
--- a/templates/panelizer-view-mode.html.twig
+++ /dev/null
@@ -1,42 +0,0 @@
-{#
-/**
- * @file
- * Template for a generic Panelizer view mode.
- *
- * Available variables:
- * - entity: The entity with limited access to object properties and methods.
- * - attributes: HTML attributes for the containing element.
- * - content: All entity items.
- * - entity_url: Direct URL of the current entity.
- * - title: The title of the entity.
- * - title_element: HTML element to use for the title (defaults to 'h2').
- * - title_attributes: Same as attributes, except applied to the main title
- * tag that appears in the template.
- * - title_prefix: Additional output populated by modules, intended to be
- * displayed in front of the main title tag that appears in the template.
- * - title_suffix: Additional output populated by modules, intended to be
- * displayed after the main title tag that appears in the template.
- * - view_mode: View mode; for example, "teaser" or "full".
- *
- * @see template_preprocess_panelizer_view_mode()
- *
- * @ingroup themeable
- */
-#}
-