{"id":18360719,"url":"https://github.com/unb-libraries/custom-entity","last_synced_at":"2025-04-10T03:37:26.682Z","repository":{"id":57075177,"uuid":"406097392","full_name":"unb-libraries/custom-entity","owner":"unb-libraries","description":"A collection of modules to ease working with custom entities in Drupal.","archived":false,"fork":false,"pushed_at":"2023-07-25T11:01:50.000Z","size":176,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"9.x-1.x","last_synced_at":"2025-03-16T07:06:29.629Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unb-libraries.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-09-13T19:08:59.000Z","updated_at":"2024-05-19T02:07:39.000Z","dependencies_parsed_at":"2024-11-05T22:31:11.211Z","dependency_job_id":"1ae69316-ab2f-4302-8158-5593d47e2d3b","html_url":"https://github.com/unb-libraries/custom-entity","commit_stats":{"total_commits":103,"total_committers":3,"mean_commits":"34.333333333333336","dds":0.01941747572815533,"last_synced_commit":"8e9c2e989b0820377ec6c00d9caf31fcae90a0f4"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unb-libraries%2Fcustom-entity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unb-libraries%2Fcustom-entity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unb-libraries%2Fcustom-entity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unb-libraries%2Fcustom-entity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unb-libraries","download_url":"https://codeload.github.com/unb-libraries/custom-entity/tar.gz/refs/heads/9.x-1.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248153882,"owners_count":21056510,"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","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":[],"created_at":"2024-11-05T22:29:40.871Z","updated_at":"2025-04-10T03:37:26.647Z","avatar_url":"https://github.com/unb-libraries.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# unb-libraries/custom-entity [![GitHub license](https://img.shields.io/github/license/unb-libraries/docker-einbaum)](https://github.com/unb-libraries/lib.unb.ca/blob/prod/LICENSE)\nA Drupal module improving the developer experience of working with **_custom entities_**. \n\n## Installation\nThe module is a composer package hosted on packagist and can be installed by running\n```sh\ncomposer require unb-libraries/custom-entity\n```\n\nor by adding it to your project's ```composer.json``` file:\n\n```json\n{\n  \"require\": {\n    \"unb-libraries/custom-entity\": \"dev-9.x-1.x\"\n  }\n}\n```\n\nEnable the module by running\n```sh\ndrush en custom_entity\n```\n\nor via the Drupal UI under ```/admin/modules```.\n\n## Usage\nThe module enhances Drupal by providing implementations of:\n\n### Access handlers\nThe ```Drupal\\custom_entity\\Entity\\Access\\EntityAccessControlHandler``` dynamically grants or denies access to an entity whether a user has permission of the form ```\u003cOPERATION\u003e \u003cENTITY_TYPE\u003e entities```.\n\nFor example, in order for a user to get permission to ```edit``` a ```node``` entity, the user would need to have the ```edit node entities``` permission assigned to them.\n\nIn order to activate the access control handler, set it in an entity's type definition:\n\n```php\n\u003c?php\n\nuse Drupal\\Core\\Entity\\ContentEntityBase;\n\n/**\n * Defines the \"my_entity\" entity type.\n *\n * @ContentEntityType(\n *   ...\n *   handlers = {\n *     ...\n *     \"access\" = \"Drupal\\custom_entity\\Entity\\Access\\EntityAccessControlHandler\"\n *   },\n *   ...\n * ) \n */\n class MyEntity extends ContentEntityBase {\n   // ...\n }\n```\n\nCurrently bundle-level permission checking is not supported by the handler.\n\n### Permission handlers\nPermissions handlers create entity permissions of the form ```\u003cOPERATION\u003e (\u003cBUNDLE\u003e) \u003cENTITY_TYPE\u003e entities```. Add permissions handler for an entity type as follows:\n\n```php\n\u003c?php\n\nuse Drupal\\Core\\Entity\\ContentEntityBase;\n\n/**\n * Defines the \"my_entity\" entity type.\n *\n * @ContentEntityType(\n *   ...\n *   handlers = {\n *     ...\n *     \"permissions\" = \"Drupal\\custom_entity\\Entity\\Access\\EntityPermissionsHandler\"\n *   },\n *   ...\n * ) \n */\n class MyEntity extends ContentEntityBase {\n   // ...\n }\n```\n\nExtend the ```Drupal\\custom_entity\\Entity\\Access\\EntityPermissionsHandler``` class to create more customized permissions.\n\n### Route handlers\nThe ```Drupal\\custom_entity\\Entity\\Routing\\HtmlRouteProvider``` enhances Drupal default HtmlRouteProvider by providing the following additional routes for any entity type that activates it:\n- ```entity.my_entity.delete-all```: creates a form route to delete ALL instances of an ```my_entity```, if according ```delete-all``` link and form handler are defined.\n- ```entity.my_entity.\u003cFORM_HANDLER\u003e```: creates a form route for a given form handler, if ```my_entity``` defines the according link.\n\nThe following defines an entity with ```entity.my_entity.delete-all``` and ```entity.my_entity.activate``` routes: \n\n```php\n\u003c?php\n\nuse Drupal\\Core\\Entity\\ContentEntityBase;\n\n/**\n * Defines the \"my_entity\" entity type.\n *\n * @ContentEntityType(\n *   ...\n *   handlers = {\n *     ...\n *     \"form\" = {\n *       \"activate\" = ...\n *     \"routing\" = \"Drupal\\custom_entity\\Entity\\Routing\\HtmlRouteProvider\"\n *   },\n *   ...\n *   links = {\n  *    \"activate\": \"/my-entities/{my_entity}/activate\",\n *     \"delete-all-form\": \"/my-entities/delete-all\",\n *   }\n * ) \n */\nclass MyEntity extends ContentEntityBase {\n  // ...\n}\n```\n\n### Field types\nThe following new entity field types are provided:\n\n#### Creator\nThis field type adds a reference to the user who initially created it to an entity. Add this field to an entity as follows:\n\n```php\n\u003c?php\n\nuse Drupal\\Core\\Entity\\ContentEntityBase;\nuse Drupal\\custom_entity\\Entity\\UserCreatedInterface;\nuse Drupal\\custom_entity\\Entity\\EntityCreatedTrait;\n\n/**\n * Defines the \"my_entity\" entity type.\n *\n * @ContentEntityType(\n *   ...\n * )\n */\nclass MyEntity extends ContentEntityBase implements UserCreatedInterface {\n \n  use EntityCreatedTrait;\n   \n  /**\n   * {@inheritdoc}\n   */\n  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {\n    $fields = parent::baseFieldDefinitions($entity_type);\n    \n    $fields[static::FIELD_CREATOR] = static::getCreatorBaseFieldDefinition($entity_type);\n    \n    return $fields;\n  }\n}\n```\n\n#### Editor\nThis field type adds a reference to the user who most recently edited an entity. Add this field to an entity as follows:\n\n```php\n\u003c?php\n\nuse Drupal\\Core\\Entity\\ContentEntityBase;\nuse Drupal\\custom_entity\\Entity\\UserEditedInterface;\nuse Drupal\\custom_entity\\Entity\\EntityChangedTrait;\n\n/**\n * Defines the \"my_entity\" entity type.\n *\n * @ContentEntityType(\n *   ...\n * )\n */\nclass MyEntity extends ContentEntityBase implements UserEditedInterface {\n \n   use EntityChangedTrait;\n   \n   /**\n   * {@inheritdoc}\n   */\n  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {\n    $fields = parent::baseFieldDefinitions($entity_type);\n    \n    $fields[static::FIELD_CREATOR] = static::getEditorBaseFieldDefinition($entity_type);\n    \n    return $fields;\n  }\n }\n```\n\n### Forms\nThe following base forms are provided:\n\n#### ConfigEntityForm\nBase form for config entities that comes with mandatory ```id``` and ```label``` fields pre-configured. Use it as follows:\n\n```php\n\u003c?php\n\nuse Drupal\\custom_entity\\Form\\ConfigEntityForm;\n\n/**\n * Form for \"my_config_entity\" entities. \n */\nclass MyConfigEntityForm extends ConfigEntityForm {\n   \n   /**\n   * {@inheritDoc}\n   */\n  public function buildForm(array $form, FormStateInterface $form_state) {\n    $form = parent::buildForm($form, $form_state);\n    \n    // add additional form fields here.\n    \n    return $form;\n  }\n }\n```\n\n#### ConfigEntityBundleForm\nBase form for config entities that are bundles of content entities. Built on top of ```ConfigEntityForm```, it allows for additional configuration of a [bundle class](https://www.drupal.org/node/3191609).\n\n### Services\n\n### Submodules\n\nMore features can be added by activating any of the following sub-modules:\n\n| Module                  | Description                                                                                                    |\n|-------------------------|----------------------------------------------------------------------------------------------------------------|\n| [custom_entity_alias](custom_entity_alias)         | Creates path aliases for views related to custom entities.                |\n| [custom_entity_events](custom_entity_events)       | Dispatch and subscribe to custom entity events.                           |\n| [custom_entity_mail](custom_entity_mail)           | Send emails upon creating, editing, deleting custom entities.             |\n| [custom_entity_revisions](custom_entity_revisions) | A collection of components to ease working with custom entity revisions.  |\n| [custom_entity_ui](custom_entity_ui)               | Enhances FieldUI to provide an administration UI for custom entity types. |\n| [custom_entity_update_n](custom_entity_update_n)   | Provides services to simplify custom entity update N hooks.               |\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funb-libraries%2Fcustom-entity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funb-libraries%2Fcustom-entity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funb-libraries%2Fcustom-entity/lists"}