{"id":21598111,"url":"https://github.com/matfish2/craft-entry-meta","last_synced_at":"2025-04-11T01:01:41.246Z","repository":{"id":62524967,"uuid":"432715734","full_name":"matfish2/craft-entry-meta","owner":"matfish2","description":"Add metadata to all element types in CraftCMS","archived":false,"fork":false,"pushed_at":"2025-01-03T15:42:46.000Z","size":118,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T21:42:31.726Z","etag":null,"topics":["craft-plugin","craftcms","metadata"],"latest_commit_sha":null,"homepage":"https://plugins.craftcms.com/entry-meta","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matfish2.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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-11-28T13:10:08.000Z","updated_at":"2025-01-03T15:42:46.000Z","dependencies_parsed_at":"2024-11-04T17:31:28.680Z","dependency_job_id":"a55f5257-78e9-4080-a3ac-9a681b60f795","html_url":"https://github.com/matfish2/craft-entry-meta","commit_stats":{"total_commits":46,"total_committers":2,"mean_commits":23.0,"dds":0.06521739130434778,"last_synced_commit":"11ea31089ef3b6be265978a03c31eaaac3fc2076"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matfish2%2Fcraft-entry-meta","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matfish2%2Fcraft-entry-meta/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matfish2%2Fcraft-entry-meta/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matfish2%2Fcraft-entry-meta/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matfish2","download_url":"https://codeload.github.com/matfish2/craft-entry-meta/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248322600,"owners_count":21084336,"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":["craft-plugin","craftcms","metadata"],"created_at":"2024-11-24T18:11:19.425Z","updated_at":"2025-04-11T01:01:41.172Z","avatar_url":"https://github.com/matfish2.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Element Meta\n\nThis package adds the ability to save schemaless metadata to all element types, including custom elements.\n\n## Why?\n\nSometimes you'll need to attach additional information to your element (e.g Entry, Product or Category) without creating a corresponding field in Craft. \nCommon examples include saving an identifier of the element in another system, keeping track of post views, or flagging an element as seeded for later removal. \n\nOne option would be to create a read-only field on Craft using a plugin that allows for hidden/read-only field types.\nHowever, there are multiple cons to this approach:\n\n1. You now have a field in your section layout that does not semantically belong there.\n2. It can be accessed, modified and deleted from the control panel (granted only on dev environment).\n3. It is loaded when creating or editing a post, which can be easily tampered with from the developer console of the\n   browser.\n4. It does not allow for ad-hoc data that could pertain to a single post or just some posts, without creating yet\n   another field.\n5. It is saved to the `content` table, which is not its natural habitat.\n\nElement Meta offers a more flexible, schemaless alternative, which by-passes the Craft data structure and allows you\nto save metadata in JSON format to a designated polymorphic table.\n\n## Installation\n\n1. Include the package:\n\n```\ncomposer require matfish/craft-entry-meta\n```\n\n2. Install the plugin:\n\n```\nphp craft plugin/install entry-meta\n```\n\n## Initial Setup\n\nOnce installed go to the plugin's settings page (Under `Settings` in the control panel).\n\n![Settings Page](https://user-images.githubusercontent.com/1510460/187615962-066465b2-4318-4d81-8de7-f54c1bf0d262.png)\n\nSelect the elements you'd like to add metadata to.\nNote that for custom elements (as opposed to Craft's native elements) you would need to provide both the Element class and the Active Record class.\nE.g if you would like to enable metadata on Craft Commerce's products:\n\nElement Class = `craft\\commerce\\elements\\Product`\n\nActive Record Class = `craft\\commerce\\records\\Product`\n\nThe package will validate both classes to ensure they exist and are children of Element and ActiveRecord respectively.\n\nOnce you save the settings the plugin will add the metadata functionality to the relevant elements.\n\n## Usage\n\n`$entry` below refers to an entry element (`craft\\elements\\Entry`).\n\nNote that the element must be already saved in order to use metadata methods.\n\nSet metadata (will replace existing metadata):\n\n```php\n$entry-\u003esetElementMetadata([\n    'foo'=\u003e'bar'\n]);\n```\n\nAdd to existing metadata, or replace an existing value:\n\n```php\n$entry-\u003eaddElementMetadata([\n    'a'=\u003e1\n]);\n```\n\nDelete metadata:\n```php\n$entry-\u003edeleteElementMetadata();\n```\n\nGet all metadata of an entry:\n\n```php\n$entry-\u003egetElementMetadata();   \n```\n\nGet a specific key value:\n\n```php\n$entry-\u003egetElementMetadata('foo');   \n```\n\nGet nested values:\n```php\n$entry-\u003egetElementMetadata('foo.bar');   \n```   \n\nOr using Twig:\n\n```twig\n{{entry.getElementMetadata('foo')}}\n```\n\n### Query by metadata\n\nYou can query by metadata on the active record class or the element class (e.g `craft\\records\\Entry`, `craft\\elements\\Entry`) using the methods detailed below.\n\nNote you should first join the metadata table using the `joinMetadata` method. This is a left join, so it doesn't affect query results, just adds the metadata column. \n\nE.g \n```twig\n{{ craft.entries().joinMetadata().whereMetadata('foo','bar') }}\n```\nor:\n```php\ncraft\\elements\\Entry::find()-\u003ejoinMetadata()-\u003ewhereMetadata('foo','bar')\n```\nor:\n```php\ncraft\\records\\Entry::find()-\u003ejoinMetadata()-\u003ewhereMetadata('foo','bar')\n```\n\n#### Filter by metadata\n##### Value\n```php\nEntry::find()-\u003ewhereMetadata('foo','bar');\n```\nFor more complex queries you can also chain `orWhereMetadata` and `andWhereMetadata`.\n\nThe method defaults to the `=` operand, which you can override on the third argument. E.g:\n```php\nEntry::find()-\u003ewhereMetadata('views',0,'\u003e');\n```\n##### Existence\nYou can also check for existence of metadata **keys**:\n```php\nEntry::find()-\u003ehasMetadata('foo');\n```\nOr, conversely:\n```php\nEntry::find()-\u003edoesntHaveMetadata('foo');\n```\nTo filter down by the existence of metadata itself, simply omit the key argument:\n```php\nEntry::find()-\u003ehasMetadata(); \n```\nor\n```php\nEntry::find()-\u003edoesntHaveMetadata(); \n```\n#### Sort by metadata\n```php\nEntry::find()-\u003ewhereMetadata('views',0,'\u003e')-\u003eorderByMetadata('views',false, true);\n```\nThe second boolean argument is whether to sort in ascending order. Defaults to `true`\n\nThe third boolean argument is whether the value is an integer. Defaults to `false`\n\n#### Nested data\nYou can search and sort by nested data using the `.` syntax:\n```php\nEntry::find()-\u003ewhereMetadata('foo.bar','baz')-\u003eorderByMetadata('foobar.baz');\n```\n### Metadata on element editor page\nBy default metadata is rendered on the sidebar along with Craft's metadata (status, created at, updated at).\nYou can disable this behaviour via the plugin settings page.\n\n## License\n\nYou can try Element Meta in a development environment for as long as you like. Once your site goes live, you are required\nto purchase a license for the plugin. License is purchasable through\nthe [Craft Plugin Store](https://plugins.craftcms.com/entry-meta).\n\nFor more information, see\nCraft's [Commercial Plugin Licensing](https://craftcms.com/docs/3.x/plugins.html#commercial-plugin-licensing).\n\n## Requirements\n\nThis plugin requires Craft CMS 3.7.0 or later.\n\n## Contribution Guidelines\n\nCommunity is at the heart of open-source projects. We are always happy to receive constructive feedback from users to\nincrementally improve the product and/or the documentation.\n\nBelow are a few simple rules that are designed to facilitate interactions and prevent misunderstandings:\n\nPlease only open a new issue for bug reports. For feature requests and questions open a\nnew [Discussion](https://github.com/matfish2/craft-entry-meta/discussions) instead, and precede [FR] to the title.\n\nIf you wish to endorse an existing FR please just vote the OP up, while refraining from +1 replies.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatfish2%2Fcraft-entry-meta","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatfish2%2Fcraft-entry-meta","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatfish2%2Fcraft-entry-meta/lists"}