{"id":21543105,"url":"https://github.com/jyodsh/drupal-snippets","last_synced_at":"2026-04-16T11:03:28.574Z","repository":{"id":148623979,"uuid":"140673794","full_name":"jyodsh/drupal-snippets","owner":"jyodsh","description":"Useful Drupal 8 snippets ","archived":false,"fork":false,"pushed_at":"2018-12-16T06:48:15.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-12T15:41:09.799Z","etag":null,"topics":["drupal","drupal-8","drupal-module","php"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jyodsh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2018-07-12T06:55:49.000Z","updated_at":"2023-03-04T11:43:58.000Z","dependencies_parsed_at":"2023-06-19T17:47:53.836Z","dependency_job_id":null,"html_url":"https://github.com/jyodsh/drupal-snippets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jyodsh/drupal-snippets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyodsh%2Fdrupal-snippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyodsh%2Fdrupal-snippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyodsh%2Fdrupal-snippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyodsh%2Fdrupal-snippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jyodsh","download_url":"https://codeload.github.com/jyodsh/drupal-snippets/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jyodsh%2Fdrupal-snippets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31882886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T09:23:21.276Z","status":"ssl_error","status_checked_at":"2026-04-16T09:23:15.028Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","drupal-8","drupal-module","php"],"created_at":"2024-11-24T05:12:58.698Z","updated_at":"2026-04-16T11:03:28.537Z","avatar_url":"https://github.com/jyodsh.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Useful Drupal 8 Snippets.\n\nThis is a list of useful Drupal snippets and functions that I often reference to enhance or improve my sites.\n \n You can refer this [blog](https://thakshashila.com/) for more detailed explanation\n\n-  [Token Replacement in Drupal](#token-replacement-in-drupal-8)\n-  [Load Drupal 8 node object from URL alias](#load-drupal-8-node-object-from-url-alias)\n-  [Render a block programmatically in drupal 8](#render-a-block-programmatically-in-drupal-8)\n\n### Token Replacement in Drupal\n```php\n//Instantiate an token object.\n$token_service = \\Drupal::token() ;\n// Pass the string which contains the token and context(Eg: node object, user object et..)\n$token_replaced = $token_service-\u003ereplace($string,['node' =\u003e $node_object ]);\n```\n### Load Drupal 8 node object from URL alias\n```php\n//Your custom URL (alias).\n$my_url_alias = 'about-me';\n// This line will return corresponding system path.\n// Lets say, '/node/15' is correcsponding path '/about-me'\n$path = \\Drupal::service('path.alias_manager')-\u003egetPathByAlias('/'.$ahurl);\nif(preg_match('/node\\/(\\d+)/', $path, $matches)) {\n// This will load the node object.\n$node = \\Drupal\\node\\Entity\\Node::load($matches[1]);\n}\n```\n### Render a block programmatically in drupal 8\n```php\n// Get the block machine name from the block configure option of the desired block.\n// And you'll get url like this /admin/structure/block/manage/bartik_search. \n// The last part of the parameter is the block id\n$block = \\Drupal\\block\\Entity\\Block::load('bartik_search');\n$block_content = \\Drupal::entityManager()\n  -\u003egetViewBuilder('block')\n  -\u003eview($block);\n \nreturn array('#markup' =\u003e drupal_render($block_content));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjyodsh%2Fdrupal-snippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjyodsh%2Fdrupal-snippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjyodsh%2Fdrupal-snippets/lists"}