diff core/lib/Drupal/Component/Plugin/PluginHelper.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/lib/Drupal/Component/Plugin/PluginHelper.php	Thu May 09 15:34:47 2019 +0100
@@ -0,0 +1,31 @@
+<?php
+
+namespace Drupal\Component\Plugin;
+
+/**
+ * A helper class to determine if a plugin is configurable.
+ *
+ * Because configurable plugins in Drupal 8 might implement either the
+ * deprecated ConfigurablePluginInterface or the new ConfigurableInterface,
+ * this static method is provided so that a calling class can determine if a
+ * plugin is configurable without checking it against a deprecated interface.
+ * In Drupal 9, this check should be reduced to checking for
+ * ConfigurableInterface only and be deprecated in favor of calling classes
+ * checking against the interface directly.
+ */
+class PluginHelper {
+
+  /**
+   * Determines if a plugin is configurable.
+   *
+   * @param mixed $plugin
+   *   The plugin to check.
+   *
+   * @return bool
+   *   A boolean indicating whether the plugin is configurable.
+   */
+  public static function isConfigurable($plugin) {
+    return $plugin instanceof ConfigurableInterface || $plugin instanceof ConfigurablePluginInterface;
+  }
+
+}