{"id":57277,"date":"2023-05-07T12:40:00","date_gmt":"2023-05-07T07:10:00","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=57277"},"modified":"2023-05-11T12:43:58","modified_gmt":"2023-05-11T07:13:58","slug":"configuration-entity-vs-content-entity-in-drupal","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/configuration-entity-vs-content-entity-in-drupal\/","title":{"rendered":"Configuration entity vs Content entity in Drupal"},"content":{"rendered":"<p><strong>What is Entity?<\/strong><br \/>\nEntities are usually recognizable concepts. For ex-employee of an organization such as persons, places, things, or events that have relevance to the database.<\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Entities in Drupal provide a structured way of storing and managing data.<\/span><\/li>\n<li>Several types of entities included in Drupal core makeup both the configuration and content of a default installation.<\/li>\n<li>Entities are specifically typed objects, with each entity type defining a class that will be used for instances of the given entity.<\/li>\n<li>Drupal entities are node (content), taxonomy term, user, comments, block, file, imagestyle.<\/li>\n<li><span style=\"font-weight: 400;\">Consistent way to access field values.\u00a0<\/span><br \/>\n<i><span style=\"font-weight: 400;\">$nodeStorage = \\Drupal::entityTypeManager()-&gt;getStorage(&#8216;node&#8217;);<\/span><\/i><i><span style=\"font-weight: 400;\">$node = $nodeStorage-&gt;load($nid);<\/span><\/i><i><span style=\"font-weight: 400;\">print_r($node-&gt;get(&#8216;field_name&#8217;)-&gt;getValue());<\/span><\/i><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3><strong>Content entity vs Configuration Entity\u00a0<\/strong><\/h3>\n<p><strong>Content entity\u00a0<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">A content entity is an item of content data, consisting of text, HTML markup, images, attached files, and other data intended to be displayed to site visitors.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Content entities are grouped into entity types, which have different purposes and are displayed in very different ways on the site. <\/span><\/li>\n<li><span style=\"font-weight: 400;\">Content Entities\u00a0<\/span><span style=\"font-weight: 400;\">Stores data inside table.<\/span><\/li>\n<\/ul>\n<p><b>Examples of Content Entities\u00a0<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Block content<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Comment<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Message<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">File<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Menu Link<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Content (node)<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Shortcut<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Taxonomy term<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">User<\/span><\/li>\n<\/ul>\n<p><strong>How to create Content Entity\u00a0 \u00a0 \u00a0<\/strong><\/p>\n<p>Lets Create a Custom Entity having the following fields :<\/p>\n<ul>\n<li>Name<\/li>\n<li>Email<\/li>\n<li>Contact number<\/li>\n<\/ul>\n<p><b>Use command\u00a0<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">drupal geco\u00a0 &#8211; created a custom Content Entity <\/span><\/li>\n<\/ul>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-57267\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-18-53-31.png\" alt=\"\" width=\"538\" height=\"266\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-18-53-31.png 538w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-18-53-31-300x148.png 300w\" sizes=\"(max-width: 538px) 100vw, 538px\" \/><\/p>\n<p>Then Adding field in (entityname).php File<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-57268\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-18-55-06.png\" alt=\"\" width=\"539\" height=\"390\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-18-55-06.png 539w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-18-55-06-300x217.png 300w\" sizes=\"(max-width: 539px) 100vw, 539px\" \/><\/p>\n<p>How it look&#8217;s in Admin<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-57269\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-18-57-10.png\" alt=\"\" width=\"537\" height=\"369\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-18-57-10.png 537w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-18-57-10-300x206.png 300w\" sizes=\"(max-width: 537px) 100vw, 537px\" \/><\/p>\n<p>After saving a content entity a entry will generate<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-57270\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-02-41.png\" alt=\"\" width=\"535\" height=\"289\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-02-41.png 535w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-02-41-300x162.png 300w\" sizes=\"(max-width: 535px) 100vw, 535px\" \/><\/p>\n<p>Stored data in a database (in rows)<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-57266\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-18-44-44.png\" alt=\"\" width=\"539\" height=\"312\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-18-44-44.png 539w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-18-44-44-300x174.png 300w\" sizes=\"(max-width: 539px) 100vw, 539px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Configuration Entity<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">They are objects that allow to storage information for configurable settings.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Configuration entities can be exported via a configuration management system.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">It is stored within the common config database table as rows. eg: image style.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Stores data inside the object<\/span><\/li>\n<\/ul>\n<p><b>Examples of Configuration Entities\u00a0<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Action<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Block<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Breakpoints<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Comment Type<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Content Type<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Date Format<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Field<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Image Style<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Language<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Menu<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Role<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Views<\/span><\/li>\n<\/ul>\n<p><strong>How to Create a Configuration Entity<\/strong><\/p>\n<p>Let&#8217;s Create Config Entity to configure settings for an API like<\/p>\n<ul>\n<li>endpoint<\/li>\n<li>access key<\/li>\n<li>secret key<\/li>\n<\/ul>\n<p><b>Using Drupal gec &#8211; created a config Entity\u00a0<\/b><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-57271\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-34-08.png\" alt=\"\" width=\"538\" height=\"262\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-34-08.png 538w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-34-08-300x146.png 300w\" sizes=\"(max-width: 538px) 100vw, 538px\" \/><\/p>\n<p>Fields<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-57276\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-35-58.png\" alt=\"\" width=\"538\" height=\"341\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-35-58.png 538w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-35-58-300x190.png 300w\" sizes=\"(max-width: 538px) 100vw, 538px\" \/><\/p>\n<p>How it look&#8217;s in Admin<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-57275\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-36-12.png\" alt=\"\" width=\"517\" height=\"286\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-36-12.png 517w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-36-12-300x166.png 300w\" sizes=\"(max-width: 517px) 100vw, 517px\" \/><\/p>\n<p>After saving a Configuration entity, it will only show a message (created\/saved), not its field entry.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-57274\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-36-32.png\" alt=\"\" width=\"458\" height=\"226\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-36-32.png 458w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-36-32-300x148.png 300w\" sizes=\"(max-width: 458px) 100vw, 458px\" \/><\/p>\n<p>Stored data in a database (In Object)<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-57273\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-36-49.png\" alt=\"\" width=\"499\" height=\"99\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-36-49.png 499w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-36-49-300x60.png 300w\" sizes=\"(max-width: 499px) 100vw, 499px\" \/><\/p>\n<p>How it&#8217;s object look like<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-57272\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-37-02.png\" alt=\"\" width=\"503\" height=\"96\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-37-02.png 503w, \/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-29-19-37-02-300x57.png 300w\" sizes=\"(max-width: 503px) 100vw, 503px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>What is Entity? Entities are usually recognizable concepts. For ex-employee of an organization such as persons, places, things, or events that have relevance to the database. Entities in Drupal provide a structured way of storing and managing data. Several types of entities included in Drupal core makeup both the configuration and content of a default [&hellip;]<\/p>\n","protected":false},"author":1582,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":238},"categories":[3602],"tags":[5211],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57277"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1582"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=57277"}],"version-history":[{"count":3,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57277\/revisions"}],"predecessor-version":[{"id":57357,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57277\/revisions\/57357"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=57277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=57277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=57277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}