{"id":15173036,"url":"https://github.com/webbywe/drupal8-example-block","last_synced_at":"2026-02-06T08:05:16.227Z","repository":{"id":91753045,"uuid":"279372958","full_name":"webbywe/drupal8-example-block","owner":"webbywe","description":"A an example of a Drupal 8 block with lazy loading, configuration, and functional tests.","archived":false,"fork":false,"pushed_at":"2020-07-18T04:13:20.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-22T06:45:41.597Z","etag":null,"topics":["drupal-8","drupal8","drupal8-module"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webbywe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-07-13T17:47:35.000Z","updated_at":"2020-07-18T04:13:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"3848fdd8-b09b-4d8d-b908-59e8da648501","html_url":"https://github.com/webbywe/drupal8-example-block","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/webbywe/drupal8-example-block","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbywe%2Fdrupal8-example-block","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbywe%2Fdrupal8-example-block/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbywe%2Fdrupal8-example-block/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbywe%2Fdrupal8-example-block/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webbywe","download_url":"https://codeload.github.com/webbywe/drupal8-example-block/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webbywe%2Fdrupal8-example-block/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267585844,"owners_count":24111577,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drupal-8","drupal8","drupal8-module"],"created_at":"2024-09-27T10:40:14.902Z","updated_at":"2026-02-06T08:05:11.207Z","avatar_url":"https://github.com/webbywe.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Example Drupal 8 custom block with functional unit test\n\nThis is an example of a Drupal 8 custom block with functional unit test for demonstration purposes.\n\nFeel free to comment or provide insight of code critiques but intent of this project\nwas to practice on Drupal 8 techniques along with providing example code for the Drupal 8 community\nfor those that would find it a useful reference.\n\n## Drupal 8 custom block and code techniques Used\n\n### Block configuration\n\nThe block has a set of configurations that can be set when\nthe Block is placed in the Drupal Block Layout.\n\nThese configurations are used for both query parameters and\noutput in the template.\n\nFor refrence: [Create a custom block](https://www.drupal.org/docs/8/creating-custom-modules/creating-custom-blocks/create-a-custom-block)\n\n### Block Lazy Loading\n\nThe block lazy loads content.\nAfter the page loads the block, a Drupal 8 ajax request is made\nto load additional data.\n\nThis allows the custom block itself to be cached but the content\nto continue to load fresh data allow the block content\nto be updated while the page continues to be cached.\n\nFor reference: [Auto-placeholdering](https://www.drupal.org/docs/8/api/render-api/auto-placeholdering)\n\n### Theme templates\n\nThe custom block outputs HTML based on a render array with data\nthat is processed in the custom block twig template.\n\nThe twig template is identified in the `hook_theme()` function in the\n`.module` file.\n\nFor reference: [Create custom twig templates for custom module](https://www.drupal.org/docs/theming-drupal/twig-in-drupal/create-custom-twig-templates-for-custom-module)\n\n### Entity Query\n\nThe Block class utilizes the Drupal 8 Entity Query to both limit\nthe range of the nodes but query nodes that match\na particular set of parameters.\n\n### Functional Unit Tests\n\nDrupal 8 functional unit tests are added for testing of the\ncustom block functionality. The test utilizes the BlockTestBase.php\nfuntional unit test Drupal 8 core class for initial base setup.\n\nThe functional tests make use of [Drupal 9 asserts](https://api.drupal.org/api/drupal/core%21modules%21block%21tests%21src%21Functional%21BlockTest.php/class/BlockTest/8.9.x)\nand avoid any that have been deprecated.\n\nFor reference: [PHPUnit Browser test tutorial](https://www.drupal.org/docs/testing/phpunit-in-drupal/phpunit-browser-test-tutorial)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebbywe%2Fdrupal8-example-block","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebbywe%2Fdrupal8-example-block","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebbywe%2Fdrupal8-example-block/lists"}