Drupal 8 / D8 https://front.id/en en Ecoembes https://front.id/en/portfolio/ecoembes <span class="field field--name-title field--type-string field--label-hidden">Ecoembes</span> <div class="clearfix text-formatted field field--name-field-detail-body field--type-text-long field--label-hidden field__item"><p>Trabajando en nuestro CMS favorito (Drupal) y haciendo uso de diversas tecnologías como Js, Jquery, CSS y Compass, hemos dado soporte a diferentes necesidades de la web en general, como componentes, sliders y gestión de contenidos. Otro reto que asumimos en este sitio, fue la creación de un tema para adaptarlo a una versión móvil. Esto se implementó para que el sitio reconozca el dispositivo desde el que estaba entrando y muestre la versión para computadoras o dispositivos móviles según sea necesario.</p> <p>En el mantenimiento de Ecoembes nos hacemos cargo en las reuniones con el cliente para dar una rápida retroalimentación sobre el impacto de los cambios, de alta prioridad y el plazo de resolución esperado.</p> <p dir="ltr"><a href="http://www.ecoembes.com/en/"><u>www.ecoembes.com/en/</u></a><span>  </span></p></div> <span class="field field--name-uid field--type-entity-reference field--label-hidden"><span lang="" about="/en/user/14" typeof="schema:Person" property="schema:name" datatype="">By Casanova</span></span> <span class="field field--name-created field--type-created field--label-hidden">Tue, 03/27/2018 - 20:52</span> <div class="field field--name-field-roles field--type-string field--label-hidden field__items"> <div class="field__item">Backend Developer</div> <div class="field__item">Frontend Developer</div> <div class="field__item">QA</div> <div class="field__item">UX</div> </div> <div class="field field--name-field-tags field--type-entity-reference field--label-hidden field__items"> <div class="field__item"><a href="/es/taxonomy/term/11" hreflang="es">JavaScript</a></div> <div class="field__item"><a href="/es/taxonomy/term/2" hreflang="es">Drupal</a></div> <div class="field__item"><a href="/es/taxonomy/term/14" hreflang="es">CSS</a></div> <div class="field__item"><a href="/en/taxonomy/term/58" hreflang="en">Drupal 8 / D8</a></div> </div> <div class="field field--name-field-collage-image field--type-image field--label-hidden field__item"> <img src="/sites/default/files/2019-03/ecoembes_2.jpg" width="1160" height="2772" alt="Varias piezas y desarrollos realizados para Ecoembes" typeof="foaf:Image" /> </div> Tue, 27 Mar 2018 18:52:17 +0000 Casanova 103 at https://front.id Drupal 8: Twig t() function with params https://front.id/en/articles/drupal-8-twig-t-function-params <div data-history-node-id="208" class="layout layout--onecol"> <div class="layout__region layout__region--content"> <div class="field field--name-node-title field--type-ds field--label-hidden field__item"> <a href="/en/articles/drupal-8-twig-t-function-params" hreflang="en">Drupal 8: Twig t() function with params</a> </div> <div class="field field--name-node-submitted-by field--type-ds field--label-hidden field__item">Submitted by By <a title="View user profile." href="/en/user/1" lang="" about="/en/user/1" typeof="schema:Person" property="schema:name" datatype="" class="username">admin</a> on Friday, July 31, 2020 - 00:39.</div> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><pre> <code class="language-twig">&lt;a href="#"&gt;{{ 'View all @type' | t({'@type' : 'articles'}) }}&lt;/a&gt;</code></pre> <p> </p> </div> </div> </div> Thu, 30 Jul 2020 22:39:47 +0000 admin 208 at https://front.id Drupal 8: Activar themes al habilitar un modulo https://front.id/es/articles/drupal-8-activar-themes-al-habilitar-un-modulo <div data-history-node-id="115" class="layout layout--onecol"> <div class="layout__region layout__region--content"> <div class="field field--name-node-title field--type-ds field--label-hidden field__item"> <a href="/en/articles/drupal-8-enable-themes-when-module-gets-enabled" hreflang="en">Drupal 8: Enable themes when a module gets enabled</a> </div> <div class="field field--name-node-submitted-by field--type-ds field--label-hidden field__item">Submitted by <span lang="" about="/en/user/10" typeof="schema:Person" property="schema:name" datatype="">By Capy</span> on Monday, October 7, 2019 - 10:00.</div> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>When you enable a Drupal module or profile, it may be useful to activate and set a theme for the end user and/or Drupal administration.</p> <p>For this type of situations I leave you a snippet of code that is placed in the <em>hook_install()</em> of some module of your own that you have out there:</p> <pre> <code>function foo_install() { $theme_list = [ 'stark', 'adminimal_theme', ]; // Install themes. \Drupal::service('theme_installer')-&gt;install($theme_list); // Get theme manager $system_theme = \Drupal::configFactory()-&gt;getEditable('system.theme'); // Set default and admin themes. $system_theme -&gt;set('default', 'stark') -&gt;set('admin', 'adminimal_theme') -&gt;save(); }</code></pre> <p> </p> <p>And that's it. When you activate the module "<strong>stark</strong>" will be activated for the end user and "<strong>adminimal_theme</strong>" for the admin part.</p> <p><strong>NOTE</strong>: This code logically works also in the <em>hook_update_N()</em> and <em>hook_uninstall()</em>.</p> <p>Bye!</p></div> </div> </div> Mon, 07 Oct 2019 08:00:00 +0000 Capy 115 at https://front.id Composer prohibits: Why my Drupal doesn’t upgrade? https://front.id/en/articles/composer-prohibits-why-my-drupal-doesnt-upgrade <div data-history-node-id="179" class="layout layout--onecol"> <div class="layout__region layout__region--content"> <div class="field field--name-node-title field--type-ds field--label-hidden field__item"> <a href="/en/articles/composer-prohibits-why-my-drupal-doesnt-upgrade" hreflang="en">Composer prohibits: Why my Drupal doesn’t upgrade?</a> </div> <div class="field field--name-node-submitted-by field--type-ds field--label-hidden field__item">Submitted by <span lang="" about="/en/user/40" typeof="schema:Person" property="schema:name" datatype="">By leandro</span> on Monday, November 26, 2018 - 07:00.</div> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>With Drupal 8, arrives Composer as the standard for dependencies management on our projects. This implies that our processes will need to be adapted to follow this new dependency management organization, like modules installation or Core upgrades.</p> <p>In this case we will talk about components upgrades, focused on how “<strong>composer prohibits</strong>” command can help us when the upgrade process doesn’t work fine. Here we will use Drupal as an example to explain how this command work, but the solution works on every project with composer as dependency manager.</p> <p>Let’s assume that we have a Drupal project with 8.5 Core version, and we'd like to upgrade to Drupal 8.6. What we would do is to execute the following:</p> <pre> <code class="language-bash">composer update drupal/core --with-dependencies</code></pre> <p>When we execute this, Composer will upgrade dependencies and needed packages, but when Composer finished, it may happen that drupal/core is still in 8.5.x version. In this moment, many people fall back to force the upgrade with “composer update”. That can bring us to many headaches, because the update command will upgrade every dependency of the project.</p> <p>It's on that moment when “<strong>composer prohibits</strong>” can help us. To check why Drupal core doesn’t upgrade, we will execute the following command:</p> <pre> <code class="language-bash">composer prohibits drupal/core:8.6.2</code></pre> <p>Composer will check what package is blocking Drupal core 8.6.2 upgrade. The command give us a list of packages that are holding back the upgrade, like the following:</p> <pre> <code class="language-bash">webflo/drupal-core-require-dev  8.5.8 requires  drupal/core (8.5.8)</code></pre> <p>As for this example, the command is telling us that “<strong>webflo/drupal-core-require-dev</strong>” needs 8.5.8 core version to work, and is blocking the core upgrade. To solve the problem, we should include this package when executing the update command:</p> <pre> <code class="language-bash">composer update drupal/core webflo/drupal-core-require-dev --with-dependencies</code></pre> <p>Now Composer will upgrade both packages, drupal core and webflo package, and Drupal will be upgraded normally.</p> <p>The <strong>composer prohibits</strong> command can be used to check if, for example, we like to upgrade some system requirement, like php version:</p> <pre> <code class="language-bash">composer prohibits php:7.2</code></pre> <p>This will tell us which packages don’t support the new php version.</p> <p>As we mentioned earlier, this isn’t an Drupal exclusive solution, so we can apply this fantastic command to any project that has Composer as dependency manager.</p> <p>References:</p> <ul> <li><a href="https://getcomposer.org/doc/03-cli.md#prohibits-why-not-">Composer documentation</a></li> </ul> </div> </div> </div> Mon, 26 Nov 2018 06:00:00 +0000 leandro 179 at https://front.id Drupal Template Helper https://front.id/en/articles/drupal-template-helper <div data-history-node-id="160" class="layout layout--onecol"> <div class="layout__region layout__region--content"> <div class="field field--name-node-title field--type-ds field--label-hidden field__item"> <a href="/en/articles/drupal-template-helper" hreflang="en">Drupal Template Helper</a> </div> <div class="field field--name-node-submitted-by field--type-ds field--label-hidden field__item">Submitted by <span lang="" about="/en/user/42" typeof="schema:Person" property="schema:name" datatype="">By keopx</span> on Tuesday, October 23, 2018 - 15:53.</div> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Drupal Template Helper is a dev tool to works with a Drupal templates on Chrome/Chromium browser.</p> <h2>Enable Drupal theme debugging and other local/dev settings</h2> <p>Drupal as debug mode for show comments with different twig template.</p> <ol> <li>Open up the <strong>settings.php</strong> file in your preferred code editor and uncomment the following lines (~ lines 767-770): <ol> <li><strong>Uncomment</strong></li> <li> <pre> <code class="language-php">if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) { include $app_root . '/' . $site_path . '/settings.local.php'; }</code></pre> </li> </ol> </li> <li>Copy the file <strong>sites/example.settings.local.php</strong> to <strong>sites/default/settings.local.php</strong> using the following terminal command, or through your display: <ol> <li> <pre> <code class="language-bash">$ cp sites/example.settings.local.php sites/default/settings.local.php</code></pre> </li> </ol> </li> <li> <p>Locate the following file <strong>default/settings.local.php </strong>and add:</p> <ol> <li> <pre> <code class="language-php">$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/default/local.services.yml';</code></pre> </li> </ol> </li> <li> <p>Create <strong>sites/default/local.services.yml</strong> file and add:</p> <ol> <li> <pre> <code class="language-yaml"># Local development services. parameters: http.response.debug_cacheability_headers: true twig.config: debug: true auto_reload: true cache: false services: cache.backend.null: class: Drupal\Core\Cache\NullBackendFactory</code></pre> <p> </p> </li> </ol> </li> <li> <p><strong>Clear cache and visit your site.</strong></p> </li> <li> <p><strong>Check </strong>an example of the potential output.</p> <ol> <li> <pre> <code class="language-twig">&lt;!-- THEME DEBUG --&gt; &lt;!-- THEME HOOK: 'node' --&gt; &lt;!-- FILE NAME SUGGESTIONS: * node--article--teaser.html.twig * node--article.html.twig * node--teaser.html.twig x node.html.twig --&gt; &lt;!-- BEGIN OUTPUT from 'core/themes/classy/templates/content/node.html.twig' --&gt;</code></pre> <p> </p> </li> </ol> </li> </ol> <h2>Drupal Template Helper</h2> <p>A Chrome DevTools extension for Drupal 8, Drupal 7 and Backdrop CMS templates:</p> <p><a href="https://chrome.google.com/webstore/detail/ppiceaegogijpjodfpiimifhbnaifbnn">https://chrome.google.com/webstore/detail/ppiceaegogijpjodfpiimifhbnaifbnn</a></p> <p><a href="https://cloud.githubusercontent.com/assets/124599/14293486/d561f37e-fb7d-11e5-8ed0-952d520678a4.png" rel="noopener noreferrer" target="_blank"><img alt="drupal-template-helper" src="https://cloud.githubusercontent.com/assets/124599/14293486/d561f37e-fb7d-11e5-8ed0-952d520678a4.png" style="max-width:100%;" /></a></p> <h2>Installation</h2> <h3>Step 1: Install and configure.</h3> <ol> <li>Download and install the Drupal Template Helper extension for Chrome.</li> <li>Click on the extension icon.</li> <li>Click on Options under Drupal Template Helper.</li> <li>Add the urls for sites to enable the extension. Example: <code>http://drupal.dev, http://www.drupal.dev.</code></li> <li>Save.</li> </ol> <h3>Step 2: Enable Chrome Experimental APIs.</h3> <ol> <li>Go to chrome://flags/#enable-devtools-experiments, find <strong>Experimental Extension APIs</strong> and <strong>Developer Tools experiments</strong>, click the "Enable" links, and restart Chrome.</li> <li>Open DevTools and click on Settings.</li> <li>Find the <strong>Experiments</strong> tab and enable <strong>Allow custom UI themes</strong>. See screenshot below. Don't forget to restart Chrome again.</li> </ol> <p><a href="https://cloud.githubusercontent.com/assets/124599/14293054/e6350e72-fb7b-11e5-973a-31794db51e4d.png" rel="noopener noreferrer" target="_blank"><img alt="drupal-template-devtools-theme-ui" src="https://cloud.githubusercontent.com/assets/124599/14293054/e6350e72-fb7b-11e5-973a-31794db51e4d.png" style="max-width:100%;" /></a></p> <p>Note: If you want to hide the Twig comments, uncheck <strong>Show HTML comments</strong> under <strong>Preferences</strong>.</p> <p><a href="https://cloud.githubusercontent.com/assets/124599/21719927/b5c16cb2-d439-11e6-8cc7-a84192aa822a.png" rel="noopener noreferrer" target="_blank"><img alt="drupal-template-devtools-preferences" src="https://cloud.githubusercontent.com/assets/124599/21719927/b5c16cb2-d439-11e6-8cc7-a84192aa822a.png" style="max-width:100%;" /></a></p> <h3>Step 3: Enable theme debug</h3> <ul> <li>For Drupal 8, see Phil's article here: <a href="https://www.chapterthree.com/blog/drupal-8-theming-setting-theme-debugging" rel="nofollow">https://www.chapterthree.com/blog/drupal-8-theming-setting-theme-debugging</a></li> <li>For Drupal 7, see <a href="https://www.drupal.org/node/223440" rel="nofollow">https://www.drupal.org/node/223440</a>.</li> </ul> <h2>Usage</h2> <p>Inspect an element using DevTools and click on Templates in the DevTools sidebar.</p> <h2>Source</h2> <ul> <li><a href="https://github.com/arshad/drupal-template-helper">https://github.com/arshad/drupal-template-helper</a></li> </ul> </div> </div> </div> Tue, 23 Oct 2018 13:53:22 +0000 keopx 160 at https://front.id Drupal 8 y 7: Modificar el peso de un hook en tu módulo para que se ejecute al final. https://front.id/es/articles/drupal-8-y-7-modificar-el-peso-de-un-hook-en-tu-modulo-para-que-se-ejecute-al-final <div data-history-node-id="3" class="layout layout--onecol"> <div class="layout__region layout__region--content"> <div class="field field--name-node-title field--type-ds field--label-hidden field__item"> <a href="/en/articles/drupal-8-y-7-modificar-el-peso-de-un-hook-en-tu-modulo-para-que-se-ejecute-al-final" hreflang="en">Drupal 8 y 7: Modificar el peso de un hook en tu módulo para que se ejecute al final.</a> </div> <div class="field field--name-node-submitted-by field--type-ds field--label-hidden field__item">Submitted by <span lang="" about="/en/user/10" typeof="schema:Person" property="schema:name" datatype="">By Capy</span> on Thursday, September 6, 2018 - 12:49.</div> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Digamos que tienes un <strong>hook_form_alter()</strong> en tu módulo y quieres modificar un label de un elemento de formulario pero después de hacer tu cambio viene otro modulo y vuelve a tocar ese label. Jode ¿a que si?</p> <p>No problemo, para eso está el <strong>hook_module_implements_alter()</strong> que nos permite especificar el orden en el que todos los módulos ejecutan un hook puntual:</p> <pre> <code>/** * Implements hook_module_implements_alter. * * Run after the path module. */ function MI_MODULO_module_implements_alter(&amp;$implementations, $hook) { if ($hook == 'form_alter') { unset($implementations['MI_MODULO']); $implementations['MI_MODULO'] = FALSE; } }</code></pre> <p>Lo que hacemos es simplemente quitar y volver a poner a a nuestro modulo dentro de la cola de orden de ejecución de ese hook (hook<strong>_form_alter</strong>()). Pero al volver a agregarlo queda puesto al final de la cola, por lo que tu módulo va a ser el último en ser ejecutado.</p> <p>Saludos!</p></div> </div> </div> Tue, 29 Nov 2016 15:05:00 +0000 Capy 3 at https://front.id Embeber componentes de drupal dentro de paragraph de forma transparente al usuario. https://front.id/en/articles/embeber-componentes-de-drupal-dentro-de-paragraph-de-forma-transparente-al-usuario <div data-history-node-id="76" class="layout layout--onecol"> <div class="layout__region layout__region--content"> <div class="field field--name-node-title field--type-ds field--label-hidden field__item"> <a href="/en/articles/embeber-componentes-de-drupal-dentro-de-paragraph-de-forma-transparente-al-usuario" hreflang="en">Embeber componentes de drupal dentro de paragraph de forma transparente al usuario.</a> </div> <div class="field field--name-node-submitted-by field--type-ds field--label-hidden field__item">Submitted by <span lang="" about="/en/user/27" typeof="schema:Person" property="schema:name" datatype="">By alvar0hurtad0</span> on Friday, December 1, 2017 - 10:23.</div> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"></div> </div> </div> Fri, 01 Dec 2017 09:23:21 +0000 alvar0hurtad0 76 at https://front.id Drupal 8: Templates a nivel form element https://front.id/en/articles/drupal-8-templates-nivel-form-element <div data-history-node-id="67" class="layout layout--onecol"> <div class="layout__region layout__region--content"> <div class="field field--name-node-title field--type-ds field--label-hidden field__item"> <a href="/en/articles/drupal-8-templates-nivel-form-element" hreflang="en">Drupal 8: Templates a nivel form element</a> </div> <div class="field field--name-node-submitted-by field--type-ds field--label-hidden field__item">Submitted by <span lang="" about="/en/user/10" typeof="schema:Person" property="schema:name" datatype="">By Capy</span> on Monday, October 16, 2017 - 18:57.</div> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Alguna vez pasa que necesitamos modificar el HTML que genera un elemento de formulario. No me refiero a un form sino mas bien al HTML que conforma un elemento de tipo <em>input</em>, <em>password</em>, <em>email</em>, <em>select</em>, etc.</p> <p>Este es un ejemplo típico del output de drupal para un campo input normal de tipo texto:</p> <p><img alt="Form input" data-entity-type="file" data-entity-uuid="64ca2958-4b97-488d-b099-05ccdb1a0f01" src="/sites/default/files/inline-images/form-input.png" /></p> <p>Y su codigo:</p> <p><img alt="Form input code" data-entity-type="file" data-entity-uuid="0b0256ef-b2fe-40d8-85eb-6c20fbc87a14" src="/sites/default/files/inline-images/form-input-code.png" /></p> <p> </p> <p>Pues bien, imaginen ahora que necesitamos que el label vaya después de la description, o que el input queremos que esté contenido en un div. Todo lo anterior requiere que tengamos control sobre el template de este tipo de campo. ¿Como lo hacemos? Vamos a ello.</p> <h2>El <a href="https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21theme.api.php/function/hook_theme_suggestions_HOOK_alter/8.4.x">hook_theme_suggestions_HOOK_alter()</a></h2> <p>Drupal de serie nos permite usar un template que ya está en el core y que contiene el HTML que se va a generar para los elementos de formulario en general. Pero nosotros queremos ir un poco mas allá y disponer de la posibilidad de modificar solo el HTML de tipos específicos de elementos de formulario. </p> <p>Para eso usamos hook_theme_suggestions_HOOK_alter() que nos permite añadir template suggestion  al template form_element (que es el que define a form-element.html.twig):</p> <pre> <code class="language-php">/** * Implements hook_theme_suggestions_HOOK_alter(). */ function MITHEME_O_MODULO_theme_suggestions_form_element_alter(array &amp;$suggestions, array $variables, $hook) { $suggestions[] = 'form_element__type__' . $variables['element']['#type']; }</code></pre> <p>¿Y que hemos conseguido con el código anterior? Pues antes del alter solo existía "f<em>orm-element.html.twig</em>" y ahora hemos conseguido tener templates granulares para cada tipo de elemento:</p> <pre> <code>// Template original que viene en el core: form-element.html.twig // Nuevos templates disponibles para que los uses en tu theme: form-element--type--textfield.html.twig form-element--type--email.html.twig form-element--type--password.html.twig form-element--type--select.html.twig form-element--type--ETCETERA.html.twig</code></pre> <h2>Hagamos algo con los templates</h2> <p>Bueno ya tenemos entendidos y bien gestionados los templates. Ahora sigamos con nuestro ejemplo. Copia "<em>form-element.html.twig"</em> desde el core o desde el theme desde el que estés heredando tu subtheme y ponlo dentro de la carpeta de "<em>templates</em>" de tu theme.</p> <p><strong>Tip</strong>: Ubicaciones de f<em>orm-element.html.twig:</em></p> <pre> <code>// Si tu theme NO hereda de algún theme del core web/core/modules/system/templates/form-element.html.twig // Si tu theme hereda de algún theme del core: web/core/themes/classy/templates/form/form-element.html.twig web/core/themes/stable/templates/form/form-element.html.twig</code></pre> <p>Y ya lo tienes!. Solo te queda limpiar el cache y modificar la posición de los label, el campo (el input), la description y hacer todo lo que necesites en dicho campo.</p> <p>Chau!</p> </div> </div> </div> Mon, 16 Oct 2017 16:57:35 +0000 Capy 67 at https://front.id Drupal 8: Crear un botón para ckeditor https://front.id/en/article/d8-crear-un-boton-para-ckeditor <div data-history-node-id="71" class="layout layout--onecol"> <div class="layout__region layout__region--content"> <div class="field field--name-node-title field--type-ds field--label-hidden field__item"> <a href="/en/article/d8-crear-un-boton-para-ckeditor" hreflang="en">Drupal 8: Crear un botón para ckeditor</a> </div> <div class="field field--name-node-submitted-by field--type-ds field--label-hidden field__item">Submitted by <span lang="" about="/en/user/10" typeof="schema:Person" property="schema:name" datatype="">By Capy</span> on Thursday, September 28, 2017 - 13:50.</div> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Botones!, una forma estupenda de conectar ckeditor con funcionalidades avanzadas de Drupal. </p> <p>En Drupal 8 tenemos un sistema realmente bueno para añadir botones a ckeditor. Necesitas saber un pelín de backend y otro de JS y poco mas. </p> <p>En este tutorial vamos a crear un boton que nos permita poner una selección de texto en "bolder". Bolder viene a ser lo siguiente a poner un texto en negrita. Hay muchas fuentes que tienen fuentes mas gruesas que la negrita. Por ejemplo Open Sans:</p> <img alt="Open Sans config sample" data-entity-type="file" data-entity-uuid="8f39a9a4-555e-47b3-bb27-2b37dfb3394e" src="/sites/default/files/inline-images/opensans-bolder-config.png" class="align-center" /> <p> </p> <h2>El backend</h2> <p>Ckeditor es un plugin creado en JS. Entonces, ¿por que necesitamos PHP?</p> <p>Fácil, porque tenemos que implementar una clase que informe unas pocas cosas al sistema para que este pueda ofrecernos el botón en la sección de configuración de ckeditor (ej: <em><strong>admin/config/content/formats/manage/full_html</strong></em>):</p> <p> </p> <figure role="group" class="caption caption-img align-center"> <img alt="Ckeditor config buttons" data-entity-type="file" data-entity-uuid="77b9bc21-6d23-4c46-b84f-c31d83e06cfd" src="/sites/default/files/inline-images/ckeditor-config-buttons.png" /> <figcaption>Ese botón marcado en rojo es nuestro plugin button</figcaption> </figure> <p> </p> <p>No te preocupes. La clase es muy simple y puedes usar como base la que hemos creado para este plugin:</p> <pre> <code class="language-php">&lt;?php namespace Drupal\ckeditor_bolder_text\Plugin\CKEditorPlugin; use Drupal\ckeditor\CKEditorPluginBase; use Drupal\ckeditor\CKEditorPluginInterface; use Drupal\editor\Entity\Editor; /** * Defines the "BolderButton" plugin. * * @CKEditorPlugin( * id = "BolderButton", * label = @Translation("CKEditor Bolder Button") * ) */ class BolderButton extends CKEditorPluginBase implements CKEditorPluginInterface { /** * {@inheritdoc} */ public function getFile() { return drupal_get_path('module', 'ckeditor_bolder_text') . '/js/bolderbutton/plugin.js'; } /** * {@inheritdoc} */ public function getConfig(Editor $editor) { return []; } /** * {@inheritdoc} */ public function getButtons() { return [ 'BolderButton' =&gt; [ 'label' =&gt; $this-&gt;t('Bolder'), 'image' =&gt; drupal_get_path('module', 'ckeditor_bolder_text') . '/js/bolderbutton/icons/bolderbutton.png', ], ]; } } </code></pre> <p>Expliquemos un poco:</p> <p>La clase la hemos creado dentro de nuestro modulo "<strong><em>ckeditor_bolder_text</em></strong>" en <em><strong>/src/Plugin/CKEditorPlugin/BolderButton.php</strong></em></p> <p>Necesita 3 metodos:</p> <p><strong>getFile()</strong> indica la ruta en la que tenemos el plugin JS de ckeditor.</p> <p><strong>getConfig()</strong> nos brinda la posibilidad de crear un formulario de configuración para configurar parámetros para el plugin. Te va a quedar mas claro con este ejemplo. El botón de imagen <img alt="Image button" data-entity-type="file" data-entity-uuid="85ab7134-c761-4f71-856f-cb3455087dbc" src="/sites/default/files/inline-images/image-button.png" />Cuando lo añades al toolbar de ckeditor te ofrece el siguiente formulario:</p> <img alt="Image button config form" data-entity-type="file" data-entity-uuid="c422bd4e-4ddd-48d8-abb4-fd013f7a8bb0" src="/sites/default/files/inline-images/image-button-config-form.png" class="align-center" /> <p><strong>getButtons()</strong> informa cual es el icono a usar en el botón y el label.</p> <p> </p> <h2>El Frontend</h2> <p>Ya declarada la clase de PHP solo nos queda crear un plugin de ckeditor que haga algo al clickear en el botón bolder:</p> <pre> <code class="language-javascript">/** * @file * Bolder plugin. */ CKEDITOR.plugins.add('BolderButton', { icons: 'bolderbutton', init: function (editor) { var bolderStyle = new CKEDITOR.style({element: 'span', attributes: {'class': 'bolder'}}); // Listen to contextual style activation. editor.attachStyleStateChange(bolderStyle, function (state) { !editor.readOnly &amp;&amp; editor.getCommand('setBolder').setState(state); }); // Register the "bold" command, which applies the bold style. editor.addCommand('setBolder', new CKEDITOR.styleCommand(bolderStyle)); editor.ui.addButton('BolderButton', { label: 'Bolder', command: 'setBolder' }); } }); </code></pre> <p>No hace falta aclarar que el archivo JS está ubicado en el path definido anteriormente en la clase de PHP en el método <em><strong>getFile()</strong></em></p> <p>La explicación de lo que hace ya corresponde mas a ckeditor que a Drupal pero vamos a ello:</p> <p><strong>var bolderStyle</strong> define un elemento de tipo &lt;span&gt; con un class "<strong>bolder</strong>". Ese span es el que se le va a aplicar al texto seleccionado cuando le demos al botón (obviamente tenemos en nuestro CSS un class .bolder{ font-weight: 800 } sino no conseguiríamos nada).</p> <p><strong>editor.attachStyleStateChange()</strong> aplica o quita el tag dependiendo de si ya estaba aplicado o no anteriormente.</p> <p><strong>editor.addCommand()</strong> define el comando "setBolder" y su acción que viene a ser aplicar bolderStyle (ver mas arriba que está explicado bolderStyle)</p> <p>Por ultimo <strong>editor.ui.addButton()</strong> añade el botón y le dice que comando ejecutar cuando sea presionado.</p> <p> </p> <h2>Resultado</h2> <img alt="Bolder ckeditor plugin working example" data-entity-type="file" data-entity-uuid="8f236221-a24c-4cf5-8a05-f1d6f4bead77" src="/sites/default/files/inline-images/bolder-working-example.png" class="align-center" /> <p> </p> <p>Chau!</p> <p> </p> </div> </div> </div> Thu, 28 Sep 2017 11:50:06 +0000 Capy 71 at https://front.id Drupal 8: Crear un usuario programáticamente https://front.id/es/articles/drupal-8-crear-un-usuario-programaticamente <div data-history-node-id="6" class="layout layout--onecol"> <div class="layout__region layout__region--content"> <div class="field field--name-node-title field--type-ds field--label-hidden field__item"> <a href="/en/articles/drupal-8-crear-un-usuario-programaticamente" hreflang="en">Drupal 8: Crear un usuario programáticamente</a> </div> <div class="field field--name-node-submitted-by field--type-ds field--label-hidden field__item">Submitted by By <a title="View user profile." href="/en/user/1" lang="" about="/en/user/1" typeof="schema:Person" property="schema:name" datatype="" class="username">admin</a> on Thursday, September 6, 2018 - 12:49.</div> <div class="clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item"><p>Cortito y conciso:</p> <pre> <code>use Drupal\user\Entity\User; $user = User::create(); $user-&gt;enforceIsNew(); $user-&gt;setEmail('mr.foo@gmail.com'); $user-&gt;setUsername('mr_foo'); $user-&gt;setPassword('foopass'); $user-&gt;activate(); $new_user = $user-&gt;save();</code></pre> <p><strong>NOTA</strong>: A partir de Drupal 8.2 <strong>el email es opcional</strong> en los usuarios (Siempre que desmarques la opción "<em>Require email verification when a visitor creates an account</em>" en /admin/config/people/accounts )</p> <p>Saludos!</p> <p> </p></div> </div> </div> Wed, 30 Nov 2016 12:04:06 +0000 Capy 6 at https://front.id