Skip to content

Instantly share code, notes, and snippets.

@ptmkenny
Created August 7, 2022 15:57
Show Gist options
  • Save ptmkenny/2df51a6f0ec16557515d81f484281a18 to your computer and use it in GitHub Desktop.
Save ptmkenny/2df51a6f0ec16557515d81f484281a18 to your computer and use it in GitHub Desktop.
Patch Drupal Feeds module 3.x to allow drush to use machine name import in addition to EID
diff --git a/src/Commands/FeedsDrushCommands.php b/src/Commands/FeedsDrushCommands.php
index bab6a1c5..3affe55f 100644
--- a/src/Commands/FeedsDrushCommands.php
+++ b/src/Commands/FeedsDrushCommands.php
@@ -408,7 +408,7 @@ class FeedsDrushCommands extends DrushCommands {
/**
* Get the feed entity by ID.
*
- * @param int $fid
+ * @param int|string $fid
* The ID of the feed.
*
* @return \Drupal\Core\Entity\EntityInterface|null
@@ -416,10 +416,25 @@ class FeedsDrushCommands extends DrushCommands {
*/
private function getFeed($fid) {
try {
- // Load the feed entity.
- return $this->entityTypeManager
- ->getStorage('feeds_feed')
- ->load($fid);
+ // Check if we have a number or a string.
+ if (!is_numeric($fid)) {
+ // This is a string, hopefully a feed type.
+ $query_type_result = \Drupal::entityQuery('feeds_feed')
+ ->condition('type', $fid)->execute();
+ if (isset($query_type_result)) {
+ foreach ($query_type_result as $only_result) {
+ // Find the result (there should only be one).
+ // Set $fid to the int ID so that we can process it.
+ $fid = $only_result;
+ }
+ }
+ }
+ if (is_numeric($fid)) {
+ // Load the feed entity.
+ return $this->entityTypeManager
+ ->getStorage('feeds_feed')
+ ->load($fid);
+ }
}
catch (InvalidPluginDefinitionException $e) {
$this->logger()->error($e->getMessage());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment