snipt

Ctrl+h for KB shortcuts

PHP

Add a class or other attribute to a Drupal form

1
2
3
function <your_theme_name_>_<your_module_name>_<your_form_name>_form_alter(&$form, &$form_state) {
  $form['#attributes'] = array('class' => '<your_class_name>');
}
https://snipt.net/embed/fb6a4b7ea1368b0d5cc8c11fefcdf78d/
https://snipt.net/raw/fb6a4b7ea1368b0d5cc8c11fefcdf78d/
fb6a4b7ea1368b0d5cc8c11fefcdf78d
php
PHP
3
2016-09-29T18:33:07
True
False
False
Jan 20, 2014 at 11:10 AM
/api/public/snipt/107206/
add-a-class-or-other-attribute-to-a-drupal-form
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="x">function &lt;your_theme_name_&gt;_&lt;your_module_name&gt;_&lt;your_form_name&gt;_form_alter(&amp;$form, &amp;$form_state) {</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> $form[&#39;#attributes&#39;] = array(&#39;class&#39; =&gt; &#39;&lt;your_class_name&gt;&#39;);</span> </span><span id="L-3"><a name="L-3"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
drupal7, php

PHP

Add class to field group on Drupal form using hook form alter

1
2
3
4
5
function <your_theme_name>_<your_form_name>_form_alter(&$form, &$form_state) {

  $form['#groups']['<your_field_group_name>']->format_settings['instance_settings']['classes'] .= ' <your_class_name>';
  
 }
https://snipt.net/embed/3e146f6c6284276e2e7a420c0663bbe0/
https://snipt.net/raw/3e146f6c6284276e2e7a420c0663bbe0/
3e146f6c6284276e2e7a420c0663bbe0
php
PHP
5
2016-09-30T20:08:28
True
False
False
Jan 20, 2014 at 09:35 AM
/api/public/snipt/107200/
add-class-to-field-group-on-drupal-form-using-hook-form-alter
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="x">function &lt;your_theme_name&gt;_&lt;your_form_name&gt;_form_alter(&amp;$form, &amp;$form_state) {</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="x"> $form[&#39;#groups&#39;][&#39;&lt;your_field_group_name&gt;&#39;]-&gt;format_settings[&#39;instance_settings&#39;][&#39;classes&#39;] .= &#39; &lt;your_class_name&gt;&#39;;</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> </span> </span><span id="L-5"><a name="L-5"></a><span class="x"> }</span> </span></pre></div> </td></tr></table>
drupal7, form, php

PHP

Drupal 7 load block view in a template file

1
2
3
4
5
<?php
      $block_to_load = block_load('views', 'your_block_name'); 
      $output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block_to_load))));       
      print $output;
?>
https://snipt.net/embed/788cb4c2cf52fd4307a1966341e748c6/
https://snipt.net/raw/788cb4c2cf52fd4307a1966341e748c6/
788cb4c2cf52fd4307a1966341e748c6
php
PHP
5
2016-10-01T08:27:02
True
False
False
/api/public/snipt/104787/
drupal-7-load-block-view-in-a-template-file
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a> <span class="nv">$block_to_load</span> <span class="o">=</span> <span class="nx">block_load</span><span class="p">(</span><span class="s1">&#39;views&#39;</span><span class="p">,</span> <span class="s1">&#39;your_block_name&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="nv">$output</span> <span class="o">=</span> <span class="nx">drupal_render</span><span class="p">(</span><span class="nx">_block_get_renderable_array</span><span class="p">(</span><span class="nx">_block_render_blocks</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="nv">$block_to_load</span><span class="p">))));</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">print</span> <span class="nv">$output</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
drupal7, php, tpl

Text only

Drush command to clear the flood table

drush sqlq 'delete from flood'
https://snipt.net/embed/321059cd00c51eedc47c81039f9ff3d4/
https://snipt.net/raw/321059cd00c51eedc47c81039f9ff3d4/
321059cd00c51eedc47c81039f9ff3d4
text
Text only
1
2016-10-01T06:00:17
True
False
False
/api/public/snipt/97903/
drush-command-to-clear-the-flood-table
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>drush sqlq &#39;delete from flood&#39; </span></pre></div> </td></tr></table>
drupal7, drush

PHP

Rendering CCK fields in Drupal 7

<?php print render($content['field_EXAMPLE']); ?> // Renders a field with the name 'EXAMPLE'
<?php print render($content['body']); ?> // Renders the 'body' field
https://snipt.net/embed/c290e253295239628d53c1f297728eb4/
https://snipt.net/raw/c290e253295239628d53c1f297728eb4/
c290e253295239628d53c1f297728eb4
php
PHP
2
2016-09-22T11:43:16
True
False
False
Nov 21, 2012 at 10:12 PM
/api/public/snipt/41203/
rendering-cck-fields-in-drupal-7
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> <span class="k">print</span> <span class="nx">render</span><span class="p">(</span><span class="nv">$content</span><span class="p">[</span><span class="s1">&#39;field_EXAMPLE&#39;</span><span class="p">]);</span> <span class="cp">?&gt;</span><span class="x"> // Renders a field with the name &#39;EXAMPLE&#39;</span> </span><span id="L-2"><a name="L-2"></a><span class="cp">&lt;?php</span> <span class="k">print</span> <span class="nx">render</span><span class="p">(</span><span class="nv">$content</span><span class="p">[</span><span class="s1">&#39;body&#39;</span><span class="p">]);</span> <span class="cp">?&gt;</span><span class="x"> // Renders the &#39;body&#39; field</span> </span></pre></div> </td></tr></table>
CCK, drupal, drupal7, php

Bash

drush change password script for drupal 7 users

drush user-password someuser --password="gr3@tP@$s"
https://snipt.net/embed/b57caad6f1d96c22b9c7065da64a9d64/
https://snipt.net/raw/b57caad6f1d96c22b9c7065da64a9d64/
b57caad6f1d96c22b9c7065da64a9d64
bash
Bash
1
2016-09-29T14:39:30
True
False
False
/api/public/snipt/36890/
drush-change-password-script-for-drupal-7-users
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>drush user-password someuser --password<span class="o">=</span><span class="s2">&quot;gr3@tP@</span><span class="nv">$s</span><span class="s2">&quot;</span> </span></pre></div> </td></tr></table>
drupal, drupal7, drush, ssh
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.