vishalkhode/spoonacular

Spoonacular module and dependencies.

dev-master 2020-12-22 12:06 UTC

This package is auto-updated.

Last update: 2024-04-22 20:02:35 UTC


README

68747470733a2f2f64727570616c697a652e6d652f73697465732f64656661756c742f66696c65732f626c6f675f706f73745f696d616765732f392e305f626c75655f7267622e706e67

Introduction

Spoonacular module is created to migrate content from Spoonacular in drupal 9. It makes use of drupal core Migrate API and Migrate Plus contributed module. Module provides following features:

  • New Recipe content type with following fields:
    • Recipe Name (Required plain text field).
    • Cooking instructions (Textarea field for adding cooking instructions for the recipe).
    • Image (Recipe Image, which is required Media field).
    • Categories (Term reference field refering to Cuisine Vocabulary).
    • Ingredient (Paragraph field for adding ingredients having following sub fields):
      • Ingredient (Term reference field refering to Ingredients Vocabulary)
      • Title (Text field)
      • Measurement Field (Custom measurement field for adding ingredient quantity, unit etc.)
    • Video (An optional text field of type Embed video).
  • Adds two vocabularies:
    • Cuisine
    • Ingredients
  • Recipe Listing page /recipes which provides list of all recipes which includes pagination & category filter at top.
  • Module configuration page /admin/config/system/spoonacular providing following configurations:
    • Use Mock API checkbox: When checked, content will be migrated from Mock API (instead of Spoonacular API).
    • Migrate recipes during CRON run ? When checked, content will be migrated automatically whenver drupal CRON runs. If you do not wish to migrate content during CRON, you can run following drush command or can add it in your scheduled jobs: drush migrate-recipes or drush mim --group=recipe.

Requirements

Download latest Drupal 9 project. You can run below command to download:

composer create-project drupal/recommended-project recipe-online

After Drupal is downloaded, download all required contributed modules:

composer require "drupal/migrate_plus"
composer require "drupal/migrate_tools"
composer require "drupal/paragraphs"
composer require "drupal/video_embed_field"

Download this spoonacular module and place it inside web/modules/custom directory.

Install the drupal 9 now with Standard profile.

  • Make sure public files directory (i.e. sites/default/files) is writable by server. If not, please provide write permission to it.
  • Make sure to set private files directory path in settings.php and verify if it's writable by server. Ex:
$settings['file_private_path'] = DRUPAL_ROOT . '/../files-private';
  • After setting private files directory, clear Drupal Caches. (This is required).
  • Create a free account in Spoonacular and get the API Key. Api Key can be found under Profile page.

Usage

  • Navigate to module install page and install Spoonacular module. Module should install successfully without any error.
  • Navigate to module configuration page (i.e. /admin/config/system/spoonacular) and you'll find different options.
  • There's a checkbox Migrate recipes during CRON run ?. When checked, content will be migrated automatically during cron runs.
  • To run cron manually, navigate to cron page (i.e /admin/config/system/cron) and click on Run Cron button.

Once cron is completed, you will see 10 recipes migrated in drupal.

Testing

Configure PHPUnit in local. You can follow steps as mentioned in drupal.org.

Following modules are required for automation testing:

composer require phpspec/prophecy-phpunit:^2 --dev
composer require behat/mink-goutte-driver --dev
composer require symfony/phpunit-bridge --dev
composer require "cweagans/composer-patches:^1.7"

There's a core issue which gives Call to undefined method error when running tests with latest PHPUnit 9.5. So, add below patch in composer.json to fix it:

"extra": {
        "enable-patching": true,
        "patches": {
          "drupal/core": {
            "Call to undefined method ::getAnnotations()": "https://www.drupal.org/files/issues/2020-12-04/3186443-1.patch"
          }
        },

Run below phpunit tests command and you should see all tests are getting executed successfully.

./vendor/bin/phpunit -c web/core/phpunit.xml web/modules/custom/spoonacular/