From 135f9377170cf8e7ee8a53b219827189116108bd Mon Sep 17 00:00:00 2001 From: Dave Reid Date: Fri, 4 Sep 2015 01:49:40 -0500 Subject: [PATCH] Adding weight to display plugins. --- src/Annotation/EntityEmbedDisplay.php | 5 +++++ src/EntityEmbedDisplay/EntityEmbedDisplayManager.php | 1 + src/Form/EntityEmbedDialog.php | 2 +- .../entity_embed/EntityEmbedDisplay/FileFieldFormatter.php | 3 ++- .../entity_embed/EntityEmbedDisplay/ImageFieldFormatter.php | 3 ++- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Annotation/EntityEmbedDisplay.php b/src/Annotation/EntityEmbedDisplay.php index 03fa2fd9..4895fa73 100644 --- a/src/Annotation/EntityEmbedDisplay.php +++ b/src/Annotation/EntityEmbedDisplay.php @@ -44,4 +44,9 @@ class EntityEmbedDisplay extends Plugin { */ public $entity_types = FALSE; + /** + * @var int + */ + public $weight = 0; + } diff --git a/src/EntityEmbedDisplay/EntityEmbedDisplayManager.php b/src/EntityEmbedDisplay/EntityEmbedDisplayManager.php index 2bfa4088..22882214 100644 --- a/src/EntityEmbedDisplay/EntityEmbedDisplayManager.php +++ b/src/EntityEmbedDisplay/EntityEmbedDisplayManager.php @@ -79,6 +79,7 @@ public function getDefinitionsForContexts(array $contexts = array()) { }); $definitions_for_context = array_intersect_key($definitions, array_flip($valid_ids)); $this->moduleHandler->alter('entity_embed_display_plugins_for_context', $definitions_for_context, $contexts); + uasort($definitions_for_context, 'Drupal\Component\Utility\SortArray::sortByWeightElement'); return $definitions_for_context; } diff --git a/src/Form/EntityEmbedDialog.php b/src/Form/EntityEmbedDialog.php index 9b2f5e4b..157ebb70 100644 --- a/src/Form/EntityEmbedDialog.php +++ b/src/Form/EntityEmbedDialog.php @@ -566,7 +566,7 @@ public function getDisplayPluginOptions(EmbedButtonInterface $embed_button, Enti $plugins = array_intersect_key($plugins, array_flip($allowed_plugins)); } - natsort($plugins); + //natsort($plugins); return $plugins; } } diff --git a/src/Plugin/entity_embed/EntityEmbedDisplay/FileFieldFormatter.php b/src/Plugin/entity_embed/EntityEmbedDisplay/FileFieldFormatter.php index 5aebe732..11a33dd0 100644 --- a/src/Plugin/entity_embed/EntityEmbedDisplay/FileFieldFormatter.php +++ b/src/Plugin/entity_embed/EntityEmbedDisplay/FileFieldFormatter.php @@ -18,7 +18,8 @@ * entity_types = {"file"}, * deriver = "Drupal\entity_embed\Plugin\Derivative\FieldFormatterDeriver", * field_type = "file", - * provider = "file" + * provider = "file", + * weight = -10 * ) */ class FileFieldFormatter extends EntityReferenceFieldFormatter { diff --git a/src/Plugin/entity_embed/EntityEmbedDisplay/ImageFieldFormatter.php b/src/Plugin/entity_embed/EntityEmbedDisplay/ImageFieldFormatter.php index e44eb9ac..cbe9449d 100644 --- a/src/Plugin/entity_embed/EntityEmbedDisplay/ImageFieldFormatter.php +++ b/src/Plugin/entity_embed/EntityEmbedDisplay/ImageFieldFormatter.php @@ -24,7 +24,8 @@ * entity_types = {"file"}, * deriver = "Drupal\entity_embed\Plugin\Derivative\FieldFormatterDeriver", * field_type = "image", - * provider = "image" + * provider = "image", + * weight = -20 * ) */ class ImageFieldFormatter extends FileFieldFormatter {