Git Product home page Git Product logo

reqres_users's Introduction

Drupal module that provides a block listing the users from a third party service. For the purposes of this test, please integrate with the https://reqres.in/ dummy API.

The block provides a paginated listing of users retrieved from the API, basic configuration of the output is possible when placing the block.

There are three extension points exposed to change sql query before it is executed, hook or event for altering response.

Installing module

Add repository to your composer.json file repositories list:

    "repositories": [
        ...
        {
            "type": "vcs",
            "url":  "https://github.com/turek/reqres_users.git"
        }
    ],

Then require module as follows:

$ composer require turek/reqres_users:dev-main

Enable module in Drupal:

$ drush en -y reqres_users

Importing users

Check if migration appears properly:

$ drush migrate:status

Execute migration:

$ drush migrate:import reqres_users

Possibly add above to cronjob.

Using block

Just place a block into content area on some page, enter configuration values as preferred and visit that page to see block in action.

Altering the query

You can alter the query by implementing below hook in your module.

function hook_query_reqres_users_query_alter(\Drupal\Core\Database\Query\AlterableInterface $query) {
  // Skip Emma from the list.
  $query->condition('first_name', 'Emma', '!=');
}

Altering output of the block

Check the ReqresUsersAlterSubscriber.php file for example implementation of event based alteration of returned data.

Another example is to use hooks, check reqres_users.api.php file for example hook implementation: hook_reqres_users_data_alter.

Altering output of the view generated block

Similar to 'Altering the query' above, but acts on the view block.

function hook_views_query_alter(Drupal\views\ViewExecutable $view, Drupal\views\Plugin\views\query\QueryPluginBase $query) {
  // Check if we are altering the correct view. Replace 'your_view_id' with the actual ID of your view.
  if ($view->id() === 'reqres_users') {
    // Example: Add a condition to exclude users with the first name 'Emma'.
    $query->addWhere('your_group', 'first_name', 'Emma', '<>');
  }
}

Running tests

Run the following command to execute unit tests for the module:

./vendor/bin/phpunit -c web/core ./web/modules/contrib/reqres_users/tests/src

reqres_users's People

Contributors

turek avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.