Module http://drupal8.ovh/en/tags/module en Render a Render array to HTML code. http://drupal8.ovh/en/tutoriels/290/render-a-render-array-to-html-code <span class="field field--name-title field--type-string field--label-hidden">Render a Render array to HTML code.</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to get HTML from drupal 8 renderer array ?<br /> How to convert Render array into HTML output code ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Fri, 02/10/2017 - 21:16</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Example :</p> <p><code>$result =  array(<br />   '#markup' =&gt; 'Hello. This is my First Page',<br /> );<br /> $renderer = \Drupal::service('renderer');<br /> $html = $renderer-&gt;render($result);</code></p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/module" hreflang="en">Module</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/100/display-contents-using-drupal8-render-api" hreflang="en">Display contents using Drupal8 Render API</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=290&amp;2=comment&amp;3=comment" token="9cfac063"></drupal-render-placeholder> </section> Fri, 10 Feb 2017 20:16:23 +0000 editor 290 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/290/render-a-render-array-to-html-code#comments Create an advances Search system for Drupal 8 with Search API. http://drupal8.ovh/en/tutoriels/284/create-a-advances-search-system-for-drupal-8-search-api <span class="field field--name-title field--type-string field--label-hidden">Create an advances Search system for Drupal 8 with Search API.</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to use advances search server like Solr, Elasticsearch, Database ... With a Drupal 8 site ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Wed, 01/18/2017 - 12:03</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h2>Search API and Database Search server.</h2> <p>1. Uninstall drupal basic Search<br /> 2. Install search_api and search_api_db<br />   NOTE : You can also use another database configures on settings.php<br /> 3. Add a Search Server (/admin/config/search/search-api/add-server).<br />   - Use "Database" as cackend server.<br /> 3. Add a Search Index (/admin/config/search/search-api/add-index).<br />   - Select Enteties (Data source) to index with this index and a search server.<br />   - Save and Add fields to Index. (Example : Title, Body file for "Contents").<br />   - Optionaly you can configure "Processors" as Filters, Data traitements ...<br /> 4. Enable the newly created "Index" then run indexing or queue indexing.<br /> 5. Create a view using your Index, and add field "Search: Fulltext search" as Exposed criteris filter.</p> <p>Once indexing is done, visit the view's page to use the search system.</p> <p> </p> <p><strong>Tips </strong>: For a quick start, just install the "Database Search Defaults" (), and configure your "Search Server", "Index" and "Search Pages" on.<br />  - Search API :        /admin/config/search/search-api<br />  - Search Views :    /admin/structure/views (Defaut : /admin/structure/views/view/search_content )</p> <p><em>NOTE : To create a server like Solr, Elasticsearch you need to install search server and the drupal module for those servers.</em></p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/search" hreflang="en">Search</a></li> <li><a href="/en/tags/module" hreflang="en">Module</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=284&amp;2=comment&amp;3=comment" token="329c2fe3"></drupal-render-placeholder> </section> Wed, 18 Jan 2017 11:03:57 +0000 editor 284 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/284/create-a-advances-search-system-for-drupal-8-search-api#comments Make Some operations Programmatically - Hook Update Deploy Tools http://drupal8.ovh/en/tutoriels/281/make-some-operations-programmatically-hook-update-deploy-tools <span class="field field--name-title field--type-string field--label-hidden">Make Some operations Programmatically - Hook Update Deploy Tools</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to make deploy operations programmatically ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Wed, 01/11/2017 - 11:33</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p><strong>Hook Update Deploy Tools</strong> is a great contrib module help to make most of site deploy operations programmatically.<br /> Link : https://www.drupal.org/project/hook_update_deploy_tools</p> <p>CAUTION : Current drupal 8 version is unstable (8.x-1.0-unstable1, 2016-Feb-07 Version),  but 8.x-1.x-dev version is usable.</p> <h3>Example: Delete a field instance.<br /> Using contrib module hook_update_deploy_tools</h3> <p>//Drupal 8:<br /> $message = \HookUpdateDeployTools\Fields::deleteInstance('taxonomy_term', 'field_name', 'tags');</p> <p>//Drupal 7:  <br /> $message = HookUpdateDeployTools\Fields::deleteInstance('taxonomy_term', 'field_name', 'tags');</p> <p> </p> <p>Without Hook Update Deploy Tools<br /> //Drupal 8:</p> <p>//Drupal 7:<br /> $instance = field_info_instance('node', 'field_name', 'page');//For node<br /> $instance = field_info_instance('taxonomy_term', 'field_name', 'tags');//For taxonomy term<br /> if ($instance) {<br />   field_delete_instance($instance);<br /> }</p> <p>//D8 (Not tested)<br /> $field_info = \Drupal\field\Entity\FieldConfig::loadByName('node', 'page', 'field_name');<br /> $field_info-&gt;delete();</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/drupal-7" hreflang="en">Drupal 7</a></li> <li><a href="/en/tags/module" hreflang="en">Module</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/223/change-drupal-8-text-field-maximum-length" hreflang="en">Change Drupal 8 text field maximum length</a></div> <div class="field__item"><a href="/en/tutoriels/263/custom-content-entity-field-types-of-drupal-8" hreflang="en">Custom Content Entity Field types of drupal 8</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=281&amp;2=comment&amp;3=comment" token="7ad0b276"></drupal-render-placeholder> </section> Wed, 11 Jan 2017 10:33:42 +0000 editor 281 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/281/make-some-operations-programmatically-hook-update-deploy-tools#comments Solr Configuration for Drupal http://drupal8.ovh/en/tutoriels/273/solr-configuration-for-drupal <span class="field field--name-title field--type-string field--label-hidden">Solr Configuration for Drupal</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to setup solr server for Drupal (Drupal 8 and Drupal 7) ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Tue, 12/13/2016 - 10:40</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Step 1. <a href="/en/tutoriels/272/install-solr-search-api">Install Tomcat And Solr Server (atlest 5.4.1)</a></p> <p>Step 2. Install Solr Search API On your drupal</p> <p>#Drush# drush en search_api_solr -y</p> <p>Step 3. Copy solr core files</p> <p>You have an example of "Solr configuration" files deleverd with drupal search_api_solr contrib module. on  <strong>search_api_solr/solr-conf/5.x. </strong>Copy this folder into the solr server core folder (Ex : /opt/solr-5.4.1/server/solr <a href="/en/tutoriels/272/install-solr-search-api">On our example</a>) and rename it (Ex: 5.x -&gt;<strong> new_core</strong>)</p> <p>Step 4. Add this core to sorl system.</p> <ul><li>Go to http://127.0.0.1:8983/solr/ (Or your server path) <ul><li>NOTE : If you use <strong>Jetty</strong> (as the example) server is at port <strong>8983</strong>, and Tomcat uses 8080 by default.</li> </ul></li> <li>Click on <strong>Core Admin</strong> -&gt; <strong>Add Core</strong> -&gt;Create New Core (Here core name is "<strong>new_core</strong>") <ul><li>If you have an error like ".../data/elevate.xml not found", copy <strong>new_core/elevate.xml</strong> file into <strong>new_core/<u>data</u>/elevate.xml</strong>.</li> </ul></li> </ul><p>Step 5. Setup Solr on drupal</p> <ul><li>Goto /admin/config/search/search_api -&gt; <strong>Add Server</strong></li> <li>Set basic data, (Name = solr_serveur ....)</li> <li>Select Service class = Solr service</li> <li>Configure Solr access <ul><li>Solr path may like /solr or /solr/CORENAME. (Ex: /solr/new_core)</li> </ul></li> <li>Create / Save Server.</li> </ul><p>Now you can view, edit, configure, index .... your solr from /admin/config/search/search_api/server/SOLR_SERVER_NAME (For the example : /admin/config/search/search_api/server/solr_serveur)</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/module" hreflang="en">Module</a></li> <li><a href="/en/tags/drupal-7" hreflang="en">Drupal 7</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=273&amp;2=comment&amp;3=comment" token="b8d4c650"></drupal-render-placeholder> </section> Tue, 13 Dec 2016 09:40:27 +0000 editor 273 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/273/solr-configuration-for-drupal#comments Switch User Block in Drupal 8 http://drupal8.ovh/en/tutoriels/198/switch-user-block-drupal-8 <span class="field field--name-title field--type-string field--label-hidden">Switch User Block in Drupal 8</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to add the 'Switch User' block on Drupal 8 ?</p> <p>How to active Drupal Devel's Switch user Block ?</p> <p>How to login as another user without entering username and password ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Fri, 07/15/2016 - 10:40</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Drupal 8 Devel module has an integrated switch user block.  This function allow you to switch users without logout/login (for the selected roles) and without entering user name and password. To activate a this block.</p> <ol><li>Enable Drupal 8 'Devel' Module (/admin/modules)</li> <li>Add the block '<span>Switch user</span>' (Catagory:Forms)  into a region you want, from<br /> '/admin/structure/block' -&gt; 'Place block'</li> <li>Configure number of users you want to show, <span>Allow entering any user name</span> ...</li> <li>By default Only the 'ADMINISTRATOR' role can use this function, but you can change it on permissions page (/admin/people/permissions).<br /><strong>CAUTION : do not allow this to <span lang="en" xml:lang="en" xml:lang="en"><span>anybody</span></span>, because they can take your site's full control</strong>.</li> </ol><p> </p> <p>Note : This function is very similar to the 'Masquerade' module but lightweight.</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/module" hreflang="en">Module</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=198&amp;2=comment&amp;3=comment" token="eb19bc72"></drupal-render-placeholder> </section> Fri, 15 Jul 2016 08:40:04 +0000 editor 198 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/198/switch-user-block-drupal-8#comments Features http://drupal8.ovh/en/tutoriels/196/features <span class="field field--name-title field--type-string field--label-hidden">Features</span> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Tue, 07/12/2016 - 11:54</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Features is a drupal contrib module enables the capture and management of features in Drupal, by providing a UI and API for taking different site building components from modules with exportables and bundling them together in a single feature module. A feature created by the 'Features module' can be checked, updated, or reverted programmatically.</p> <p>In Drupal 7, <strong><em>Strongarm </em></strong>module allows to export/import/edit drupal variables. In Drupal 8, It is included with core modules.</p> <p>Organize your Features</p> <p><code>/site/all/features<br />  - blocks/<br />  - content_types/<br />  - env/<br />  - feeds/<br />  - menus/<br />  - permissions/<br />  - roles/<br />  - settings/<br />  - taxonomy/<br />  - views/</code></p> <p> </p> <p>Also visit : <a href="/en/tutoriels/205/organize-features-on-drupal">Organize the Features on Drupal</a></p> <p>Detailing structure (Example)</p> <p><code>site/all/features/<br />  - blocks/<br />     #Create a feature per block or a blocks group, Ex:<br />     - site_fs_block_header/<br />     - site_fs_blocks_menu/<br />  - content_types/<br />     #Create a feature per content type<br />     #Do not add field base, field group and field instance to the content type feature<br />     - site_fs_ct_article<br />     - site_fs_ct_basicpage<br />  - menus/<br />     #Preferancely, Create one feature per menu or one per group of menu if they contains just 2/3... itmes. Do not add other settings<br />     - site_fs_menu_main<br />     - site_fs_menu_footer<br />     - site_fs_menu_mymenu<br />  - permissions/ (and roles)<br />     #You can create one feature for all permissions or split as you want<br />     - site_fs_permissions/<br />      #You can create one feature for all roles or split as you want<br />     - site_fs_roles/<br />  - settings/<br />     #Group all your settings by catagory, Ex:<br />     - site_fs_ckeditor/        #With ckeditor frofiles, settings ...<br />     - site_fs_dependencies/    #dependencies: Modules and also features<br />     - site_fs_field_base/    #Basic fields settings<br />     - site_fs_lang_fr/        #Language settings Ex : French<br />     - site_fs_site_settings/#Other settings of the site<br />     - site_fs_user/            #User settings<br />     - site_fs_worklow/        #Other modules settings Ex: Workflow ...<br />     - site_fs_linkit_prof/    #Linkit Profiles<br />     - site_fs_pathauto/        #Pathauto settings<br />     - ...<br />  - taxonomy/<br />     #Preferancely, Create one feature per vocabulary but you can arrange as you want.<br />     - site_fs_taxo_tags<br />     - site_fs_taxo_all ...<br />  - views/<br />     #Create one feature per view, do not include any other settings the views<br />     - site_fs_view1<br />     - site_fs_view2 ...</code><br />  </p> <p> </p> <p> </p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/drupal-7" hreflang="en">Drupal 7</a></li> <li><a href="/en/tags/features" hreflang="en">Features</a></li> <li><a href="/en/tags/module" hreflang="en">Module</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/205/organize-features-on-drupal" hreflang="en">Organize the Features on Drupal</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=196&amp;2=comment&amp;3=comment" token="92f59e23"></drupal-render-placeholder> </section> Tue, 12 Jul 2016 09:54:53 +0000 editor 196 at http://drupal8.ovh Create a simple module to use Drupal 8 Hook System http://drupal8.ovh/en/tutoriels/193/create-a-simple-module-to-use-drupal-8-hook-system <span class="field field--name-title field--type-string field--label-hidden">Create a simple module to use Drupal 8 Hook System</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>What are the drupal hooks and how to use drupal hooks ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Fri, 07/08/2016 - 10:58</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><h2>Drupal 8 Hook System</h2> <p>Hooks allow modules to alter the drupal core behavior or another module. Hooks are discovered and called at specific times to alter or add to the base behavior or data (invoking the hook). Each hook has a name start with hook_ (Ex; hook_menu()). Your modules can also define their own hooks, in order to let other modules interact with them.</p> <p>How to use drupal hooks ?</p> <p>1. Create a custom module (See <a href="/en/tutoriels/3/create-a-simple-module-for-drupal-8">Create a simple module</a>).<br /> Hire module name is '<strong>test</strong>'</p> <p>2. Add a php file with <strong>.module</strong> extention at the root of the module called THEMODULENAME.module<br /> Hire File name is test.module</p> <p>3. Now you can implement any drupal 8 hook in this file</p> <p><strong>To implement a hook, you must replace hook_ by YourModuleName_. Ex <code>hook_help()</code> become <code>test_help()</code></strong></p> <p>Example: Implement hool_help();</p> <p><code>&lt;?php<br /> /**<br />  * Implements hook_help().<br />  *<br />  * Displays help and module information.<br />  *<br />  * @param path<br />  *   Which path of the site we're using to display help<br />  * @param arg<br />  *   Array that holds the current path as returned from arg() function<br />  */<br /> function <strong> test</strong>_help($path, $arg) {<br />   switch ($path) {<br />     case "help.page.<strong>test</strong>":<br />       return '' . t("Hello, This is my first hook") . '';<br />       break;<br />   }<br /> } </code></p> <p>4. Then Visit /admin/help/test to Test your Hook<br /> If you can see the message "Hello, This is my first hook", it's work.</p> <p> </p> <p>More about Extending and altering Drupal : https://api.drupal.org/api/drupal/core%21core.api.php/group/extending/8.2.x</p> </div> <div class="field field--name-field-file field--type-file field--label-inline"> <div class="field__label">File</div> <div class="field__item"> <span class="file file--mime-application-zip file--package-x-generic"> <a href="http://drupal8.ovh/sites/drupal/files/2016-07/test_hook_system.zip" type="application/zip; length=795">test_hook_system.zip</a></span> </div> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/module" hreflang="en">Module</a></li> <li><a href="/en/tags/hook" hreflang="en">Hook</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/3/create-a-simple-module-for-drupal-8" hreflang="en">Create a simple module for Drupal 8 - Step 1</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=193&amp;2=comment&amp;3=comment" token="dab903b6"></drupal-render-placeholder> </section> Fri, 08 Jul 2016 08:58:10 +0000 editor 193 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/193/create-a-simple-module-to-use-drupal-8-hook-system#comments Drupal 8 Tags based cache system http://drupal8.ovh/en/tutoriels/155/drupal-8-tags-based-cache-system <span class="field field--name-title field--type-string field--label-hidden">Drupal 8 Tags based cache system</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to use the tags based cache system of drupal 8 ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Tue, 06/07/2016 - 13:52</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>This system allow you to invalidate drupal cache using a 'tag'</p> <p>Exapples:</p> <p><code>\Drupal\Core\Cache\Cache::invalidateTags(array ('config:views.view.front'));<br /> \Drupal\Core\Cache\Cache::invalidateTags(array ('config:system.performance'));<br /> \Drupal\Core\Cache\Cache::invalidateTags(array ('user:1'));<br /> \Drupal\Core\Cache\Cache::invalidateTags(array ('node:1'));</code></p> <h2>Tags Syntax</h2> <p>A cache tag is a string like thing:identifier</p> <p>Examples:</p> <p><code>node:1</code> - cache tag for Node entity 1 (invalidated whenever it changes)<br /><code>user:1</code> - cache tag for User entity 1 (invalidated whenever it changes)<br /><code>config:system.performance</code> -  cache tag for the system.performance configuration<br /><code>config:views.view.front</code> - cache tag for the front view configuration<br /> And also:<br /><code>library_info</code> - cache tag for asset libraries<br /><code>route_match</code> - cache tag for a path (Route)<br /><code>node_list</code> - list cache tag for Node entities (invalidated whenever any Node entity is updated, deleted or created, i.e. when a listing of nodes may need to change)</p> <h2>How to find the tag names ?</h2> <p>You can yse the <code>::getCacheTags()</code> method of Entity based classes to know tag names.</p> <p>For the Views:</p> <p><code>$tags = \Drupal\views\Entity\View::load('front')-&gt;getCacheTags();</code></p> <p>For the users:</p> <p><code>$tags = \Drupal\views\Entity\View::load('news')-&gt;getCacheTags();</code></p> <p> </p> <p>Cache by route name (route_match)</p> <p>Some datas are cached using the URL/Path and the tag 'route_match'. Fot that, invalidate cache bu <strong>CID </strong>(cache ID)<br /> Example:</p> <p><code>route_match<br /> Page : /admin<br /> cid  : route:/admin:<br /> tags : route_match</code></p> <p>For a custom Page , View, Node ...<br /> tags : route_match<br /> cid  :<br /><code>route:/node/10:<br /> route:/node/10:_wrapper_format=drupal_ajax</code></p> <p>tags : route_match<br /> cid  :<br /><code>route:/thapathato/myview:<br /> route:/thapathato/myview:_wrapper_format=drupal_ajax</code></p> <p>  </p> <p>Link : https://www.drupal.org/developing/api/8/cache/tags</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/cache" hreflang="en">Cache</a></li> <li><a href="/en/tags/module" hreflang="en">Module</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=155&amp;2=comment&amp;3=comment" token="38fc75e6"></drupal-render-placeholder> </section> Tue, 07 Jun 2016 11:52:10 +0000 editor 155 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/155/drupal-8-tags-based-cache-system#comments Change Drupal 8 'Powered By' block http://drupal8.ovh/en/tutoriels/150/change-drupal-8-powered-by-block <span class="field field--name-title field--type-string field--label-hidden">Change Drupal 8 &#039;Powered By&#039; block</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to edit the Drupal 8 system's "Powered By" block ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Tue, 05/31/2016 - 13:30</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>You can't change the body of this block fron the user interface. But you can do that using a small <a href="/en/tutoriels/5/create-a-simple-module-for-drupal-8-step-2-create-simple-page">custom module</a> using hook_block_view_alter().</p> <p>Example: in the yourmodule.module</p> <p><code>function yourmodule_block_view_alter(array &amp;$build, \Drupal\Core\Block\BlockPluginInterface $block) {<br />   if ($block-&gt;getBaseId() === 'system_powered_by_block') {<br />     $build['#pre_render'][] = '_yourmodule_block_poweredby_prerender';<br />   }<br /> }</code></p> <p><code>function _yourmodule_block_poweredby_prerender(array $build) {<br />     $build['content']['#markup'] = 'Your text';<br />     return $build;<br /> }</code></p> <p>Then <a href="/en/tutoriels/147/cache-clearing-and-rebuilding-methods-for-drupal-8">clear the cache</a></p> <p>NOTE: You can also remove the system 'Powered by Drupal' block and replace by a custom block.</p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/module" hreflang="en">Module</a></li> </ul> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=150&amp;2=comment&amp;3=comment" token="70b0e873"></drupal-render-placeholder> </section> Tue, 31 May 2016 11:30:56 +0000 editor 150 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/150/change-drupal-8-powered-by-block#comments Find Entity using Drupal EntityQuery http://drupal8.ovh/en/tutoriels/149/find-entity-using-drupal-entityquery <span class="field field--name-title field--type-string field--label-hidden">Find Entity using Drupal EntityQuery</span> <div class="clearfix text-formatted field field--name-field-question field--type-text-long field--label-above"> <div class="field__label">Question</div> <div class="field__item"><p>How to Find Entity (nodes, taxonomy terms, users ...) using Drupal EntityQuery ?</p> </div> </div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> <span class="field field--name-created field--type-created field--label-hidden">Sun, 05/29/2016 - 11:38</span> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>You can find any entity using Drupal 8 EntityQuery System.</p> <h2>Example 1. Taxonomy</h2> <p>Get list of all taxonomy terms<br /><code>    $query = \Drupal::entityQuery('taxonomy_term');<br />     $tids = $query-&gt;execute();</code><br /> Get term id of the vocabulary '<strong>tags</strong>'<br /><code>    $query = \Drupal::entityQuery('taxonomy_term');<br />     $query-&gt;condition('vid', 'tags');<br />     $tids = $query-&gt;execute();</code></p> <h2>Example 2. Node</h2> <p>Find all nodes where the title contains 'drupal'<br /><code>    $query = \Drupal::entityQuery('node');<br />     $query-&gt;condition('title', '%drupal%','LIKE');<br />     $nids = $query-&gt;execute();</code></p> <h2>Example 3. User</h2> <p>Fiend all users who's name contains 'admin'<br /><code>    $query = \Drupal::entityQuery('user');<br />     $query-&gt;condition('name', '%admin%','LIKE');<br />     $ids = $query-&gt;execute();</code></p> <h2>Example 4. Node with OR condition</h2> <p><code>    $query = \Drupal::entityQuery('node');<br />     $group = $query-&gt;orConditionGroup()<br />         -&gt;condition('type', 'page')<br />         -&gt;condition('type', 'article');<br />     $entity_ids = $query<br />         -&gt;condition('title', '%drupal%','LIKE')<br />         -&gt;condition($group)<br />         -&gt;execute();</code></p> <p> </p> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-inline clearfix"> <h3 class="field__label inline">Tags</h3> <ul class="links field__items"> <li><a href="/en/tags/drupal-8" hreflang="en">Drupal 8</a></li> <li><a href="/en/tags/code" hreflang="en">Code</a></li> <li><a href="/en/tags/module" hreflang="en">Module</a></li> </ul> </div> <div class="field field--name-field-related-contents field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/en/tutoriels/159/database-basic-examples" hreflang="en">Database Basic Examples</a></div> <div class="field__item"><a href="/en/tutoriels/73/database-like-condition" hreflang="en">Database LIKE condition</a></div> </div> <section class="field field--name-comment field--type-comment field--label-above comment-wrapper"> <h2 class="title">Comments</h2> <a id="comment-41"></a> <article role="article" data-comment-user-id="0" about="/en/comment/41" typeof="schema:Comment" class="comment js-comment by-anonymous clearfix"> <span class="hidden" data-comment-timestamp="1465393417"></span> <footer class="comment__meta"> <article typeof="schema:Person" about="/user/0" class="profile"> </article> <p class="comment__author"><span rel="schema:author"><span lang="" typeof="schema:Person" property="schema:name" datatype="">Adrien Lasserre (not verified)</span></span> </p> <p class="comment__time">Wed, 06/08/2016 - 15:43 <span property="schema:dateCreated" content="2016-06-08T13:43:37+00:00" class="rdf-meta hidden"></span> </p> <p class="comment__permalink"><a href="/en/comment/41#comment-41" hreflang="en">Permalink</a></p> </footer> <div class="comment__content"> <h3 property="schema:name" datatype=""><a href="/en/comment/41#comment-41" class="permalink" rel="bookmark" hreflang="en">How to query user by role</a></h3> <div property="schema:text" class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>For a role named 'reviewer' :</p> <p> $uids = \Drupal::entityQuery('user')-&gt;condition('roles.target_id','reviewer')-&gt;execute();</p> <p>Voilàa</p> <p> </p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=41&amp;1=default&amp;2=en&amp;3=" token="f55c5acf"></drupal-render-placeholder> </div> </article> <div class="indented"><a id="comment-42"></a> <article role="article" data-comment-user-id="2" about="/en/comment/42" typeof="schema:Comment" class="comment js-comment by-node-author clearfix"> <span class="hidden" data-comment-timestamp="1465820290"></span> <footer class="comment__meta"> <article typeof="schema:Person" about="/en/users/editor" class="profile"> </article> <p class="comment__author"><span rel="schema:author"><span lang="" about="/en/users/editor" typeof="schema:Person" property="schema:name" datatype="">editor</span></span> </p> <p class="comment__time">Mon, 06/13/2016 - 14:18 <span property="schema:dateCreated" content="2016-06-13T12:18:10+00:00" class="rdf-meta hidden"></span> </p> <p class="comment__permalink"><a href="/en/comment/42#comment-42" hreflang="en">Permalink</a></p> <p class="visually-hidden">In reply to <a href="/en/comment/41#comment-41" class="permalink" rel="bookmark" hreflang="en">How to query user by role</a> by <span lang="" typeof="schema:Person" property="schema:name" datatype="">Adrien Lasserre (not verified)</span></p> </footer> <div class="comment__content"> <h3 property="schema:name" datatype=""><a href="/en/comment/42#comment-42" class="permalink" rel="bookmark" hreflang="en">Merci</a></h3> <div property="schema:text" class="clearfix text-formatted field field--name-comment-body field--type-text-long field--label-hidden field__item"><p>Thank you</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=42&amp;1=default&amp;2=en&amp;3=" token="ca97245a"></drupal-render-placeholder> </div> </article> </div> <h2 class="title comment-form__title">Add new comment</h2> <drupal-render-placeholder callback="comment.lazy_builders:renderForm" arguments="0=node&amp;1=149&amp;2=comment&amp;3=comment" token="9f01aed1"></drupal-render-placeholder> </section> Sun, 29 May 2016 09:38:28 +0000 editor 149 at http://drupal8.ovh http://drupal8.ovh/en/tutoriels/149/find-entity-using-drupal-entityquery#comments