From 9174152d1060782e9ba5767b2d346ce9852cbda2 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Mon, 7 Mar 2022 15:59:13 +0200 Subject: [PATCH] Expose ::isBaseField(). Fixes #242. --- src/Drupal/Driver/BaseDriver.php | 7 +++++++ src/Drupal/Driver/Cores/CoreInterface.php | 13 +++++++++++++ src/Drupal/Driver/Cores/Drupal6.php | 8 ++++++++ src/Drupal/Driver/Cores/Drupal7.php | 8 ++++++++ src/Drupal/Driver/DriverInterface.php | 13 +++++++++++++ src/Drupal/Driver/DrupalDriver.php | 7 +++++++ 6 files changed, 56 insertions(+) diff --git a/src/Drupal/Driver/BaseDriver.php b/src/Drupal/Driver/BaseDriver.php index f5e1622b..41ba9a69 100644 --- a/src/Drupal/Driver/BaseDriver.php +++ b/src/Drupal/Driver/BaseDriver.php @@ -133,6 +133,13 @@ public function isField($entity_type, $field_name) { return FALSE; } + /** + * {@inheritdoc} + */ + public function isBaseField($entity_type, $field_name) { + return FALSE; + } + /** * {@inheritdoc} */ diff --git a/src/Drupal/Driver/Cores/CoreInterface.php b/src/Drupal/Driver/Cores/CoreInterface.php index 89c2a086..03f728d5 100644 --- a/src/Drupal/Driver/Cores/CoreInterface.php +++ b/src/Drupal/Driver/Cores/CoreInterface.php @@ -159,6 +159,19 @@ public function getFieldHandler($entity, $entity_type, $field_name); */ public function isField($entity_type, $field_name); + /** + * Checks if the specified field is a Drupal base field. + * + * @param string $entity_type + * The entity type to check. + * @param string $field_name + * The field name to check. + * + * @return bool + * TRUE if the given field is a base field, FALSE otherwise. + */ + public function isBaseField($entity_type, $field_name); + /** * Returns array of field types for the specified entity. * diff --git a/src/Drupal/Driver/Cores/Drupal6.php b/src/Drupal/Driver/Cores/Drupal6.php index 85bbe23c..f8573950 100644 --- a/src/Drupal/Driver/Cores/Drupal6.php +++ b/src/Drupal/Driver/Cores/Drupal6.php @@ -471,6 +471,14 @@ public function isField($entity_type, $field_name) { return isset($map[$field_name]); } + /** + * {@inheritdoc} + */ + public function isBaseField($entity_type, $field_name) { + // Base fields are only supported in Drupal 8 and higher. + return FALSE; + } + /** * {@inheritdoc} */ diff --git a/src/Drupal/Driver/Cores/Drupal7.php b/src/Drupal/Driver/Cores/Drupal7.php index 7c8d1332..d9c51f6f 100644 --- a/src/Drupal/Driver/Cores/Drupal7.php +++ b/src/Drupal/Driver/Cores/Drupal7.php @@ -477,6 +477,14 @@ public function isField($entity_type, $field_name) { return !empty($map[$field_name]) && array_key_exists($entity_type, $map[$field_name]['bundles']); } + /** + * {@inheritdoc} + */ + public function isBaseField($entity_type, $field_name) { + // Base fields are only supported in Drupal 8 and higher. + return FALSE; + } + /** * {@inheritdoc} */ diff --git a/src/Drupal/Driver/DriverInterface.php b/src/Drupal/Driver/DriverInterface.php index ed39f329..5519533e 100644 --- a/src/Drupal/Driver/DriverInterface.php +++ b/src/Drupal/Driver/DriverInterface.php @@ -153,6 +153,19 @@ public function roleDelete($rid); */ public function isField($entity_type, $field_name); + /** + * Checks if the specified field is a Drupal base field. + * + * @param string $entity_type + * The entity type to check. + * @param string $field_name + * The field name to check. + * + * @return bool + * TRUE if the given field is a base field, FALSE otherwise. + */ + public function isBaseField($entity_type, $field_name); + /** * Returns a configuration item. * diff --git a/src/Drupal/Driver/DrupalDriver.php b/src/Drupal/Driver/DrupalDriver.php index 39bff9cc..50489710 100644 --- a/src/Drupal/Driver/DrupalDriver.php +++ b/src/Drupal/Driver/DrupalDriver.php @@ -285,6 +285,13 @@ public function isField($entity_type, $field_name) { return $this->getCore()->isField($entity_type, $field_name); } + /** + * {@inheritdoc} + */ + public function isBaseField($entity_type, $field_name) { + return $this->getCore()->isBaseField($entity_type, $field_name); + } + /** * {@inheritdoc} */