Friday, August 1, 2014

Drupal 7 - Omega 4.x with Sass - how to add a css to the theme

(this is a post under construction, more or less. I am digging into the omega4 -Sass - theming setup framework. Just rather pissed off by spending two whole days on installing RVM - one of the prerequisites for using Sass - on my mac. Will write a blog about that process, when I don't feel the need for strong langiuage anymore. This is just a post about simple tasks you wnat to perform and which nonody seems to want to add to the documentation. Probably because only fools like me don't know how to perform these simple tasks....)
DPMS Panther LRT-SASS 7.62 NATO



This post supposes you have an omega 4 subtheme installed and the Sass environment set up and you have the guard running on your subtheme folder (bundle exec guard)
(see f.i. http://www.code.binarybrand.com/index.php?title=Omega_4)


1. Open your subtheme info file (in this example my subtheme is called rli2015, so we open  rli2015.info)
2. Add a line in the stylesheets section
 stylesheets[all][] = css/rli2015.mobile.css
3. navigatie to your sass folder (in this example themes/rli2015/sass) and add a file
rli2015.mobile.scss
4. Imediately a file rli2015.mobile.css will me generated in your css folder
5. This css file will also be added to your rendered page


Sunday, July 27, 2014

Drupal - Got error 28 from storage engine query

So I had one site with suddenly error 28.

Warning: Got error 28 from storage engine query: SELECT DISTINCT b.* FROM blocks b LEFT JOIN blocks_roles r ON b.module = r.module AND b.delta = r.delta LEFT JOIN i18n_blocks i18n ON (b.module = i18n.module AND b.delta = i18n.delta) WHERE (i18n.language ='nl' OR i18n.language ='' OR i18n.language IS NULL) AND ( b.theme = 'seven' AND b.status = 1 AND (r.rid IN (2,4) OR r.rid IS NULL) )ORDER BY b.region, b.weight, b.module in /var/hosting/sobibor/longshadowofsobibor.com/includes/database.mysql.inc on line 148

As of the site contents I usually first suspect a hacker with extreme right wing sympathies to have destroyed part of the site.
But the issue was very simple and unbiased: Not enough diskspace!


Right wing disk thrower


Drupal 6 to Drupal 7 migration of Audiofields: a missing filefields problem

During a recent D6 to D7 upgrade I got stuck on an irritating problem. Although the filefield module has been included in D7 core, during the migrate fields action the system kept presenting me with the impossibility to migrate filefields from the d6 definitions.

PROBLEM

  • Missing field module: 'filefield'. This field cannot be migrated.
  • Missing formatter: The 'hidden' formatter used in 1 view modes for the field_advies_audio field is not available, these displays will be reset to the default formatter.

    The reason for this problem is that the field has a widget_type audiofield_widget and a widgetmodule audiofield. So I naturally tried to upgrade the audiofield module, but this does not solve the problem. CCK migration simply refuses to migrate these fields. Dunno why exactly.  (Instead of Missing field module: 'filefield'. This field cannot be migrated. a better error message would be: Won't do audiofields. Don't fucking like them. Sue me.)

  • Whaaaat??


    SOLUTION

    Manually change the widget_type to filefield_widget and the widget_module to filefield. You can do this via phpmyadmin for instance. Or to do this for the multiple audiofield we've defined, run this query

    update {content_node_field_instance}
       set widget_type = 'filefield_widget', widget_module = 'filefield'
              where widget_module = 'audiofield';

    If you run it directly use the table name with prefix. The above you can run in Devel.

    I will post here lateron how to adress the presentation in the final upgraded site.


    Tuesday, April 8, 2014

    Drupal - cron memory exhausted trails and tribulations

    Having a Cron job
    So, sometimes you simply miss a cron fail. That happens. Your client calls:
    Hey, the notifications stopped.
    New pages don't show up in the search results.
    Collections not getting indexed.
    A service is down.
    Whatever!

    And I always forget how to solve it. I just rumble along. Sometimes I increase the memory limit, the execution times never works (is hard coded in common inc I believe to be 240 or something), shut down one of the modules, ini_set this, ini_set that,  prune some tables, pray, curse.....

    I must say I utterly dislike cron fails as they are so terribly boring. So  I wanted to write an eloquent and excellent blog about all my cron resolving adventures, just to add some meaning to this annoying part of my life. But then, opening my development and maintenance logs, I remembered: There is no need for me to write anything.
    If you have a cron problem, simply visit https://drupal.org/node/553430 and tell them I sent you.


    Thursday, March 20, 2014

    Drupal - access denied page after login

    Today I got an access denied page after login, just rerooting me to the login page. I 've got this before, on a number of very different sites. Usually this problem coincides with big other problems in the website concerned, so you really can do without this annoying access problem.
    There can be an infinite number of causes: Crashed sessions table, changes in apache, php upgrades, butterflies in Australia....
    Here is my short track to quickly regain access to the site:


    Solution 1
    Truncate the sessions table and then try again

    It is perfectly save to truncate the sessions table although all currently logged in users are then logged out.  The sessions table keeps track of all user sessions on your site. It has an entry for every user/browser combination that's logged in to your site. (Logging in from firefox and from chrome creates two entries in this table, and the same goes for logging in from different devices)

    Solution 2
    Add cookie domain setting to your settings.php file, like this
    $cookie_domain = '.mydomain.ext';
    And then try again

    (see also https://drupal.org/node/1005570)


    Solution 3
    When your sessions table is crashed, simply repair table and try again


    Solution 4
    Find a religion that suits you bests and make an offering to the God or Gods who are proclaimed to be most helpful to developers by this chosen religion.....


    Drupal - unable to overwrite the settings.php

    The funny thing about drupal is it protects your files and permissions automatically. But sometimes I feel like a pilot in a plane where I do not know some of the automation.
    For instance, sometimes you want to overwrite the settings.php file and you do not have the permissions as the FTP user. Here is first a simple set of steps how to proceed.

    Problem: 
    You want to make changes to settings.php but are not allowed to overwrite.

    Cause:
    Drupal automatically sets the following permissions on your default folder and on your settings.php therein

    dr-xr-xr-x 3 {user} {group} 4096 Mar 20 12:31 default
    -r-xr-xr-x  1 {user} {group} 10516 Mar 20 10:27 settings.php


    The user being your ftp user then is not allowed to write into the default folder, nor to overwrite the settings.php file.
    Which is good, of course, but we temporarily want to be bad.


    Solution:
    What you want is to change the permissions, overwrite settings.php, and then reset the permissions to what they where.

    1. login to your server shell and navigate to your site
    cd /var/www/vhosts/domain.ext/sites
    2. change the permissions of the default folder
    sudo chmod a+w default
    3. enter the default directory
    cd default
    4. change permissions of your settings.php (oooow, spooky...)
    sudo chmod 777 settings.php
    5. Now overwrite the settings.php with your FTP program.6. To restore the permissions of the default folder and the settings.php file just login to your site, go to administer -> reports -> status report

    admin/reports/status
    7. running ls -l in your terminal will show you that all permissions are magically restored. Hail Drupal.

    Step 6 is maybe like a braindead way of restoring the permissions, but it is the good way of doing this, let drupal handle this stuff, and you point your brain to problems that are interesting on a human level....



    Tuesday, February 25, 2014

    Drupal 7 - Creating a contentype with repeatable expandable fieldcollections

    I want to make me a simple to manage contenttype containing fields and field collections that I can present as collapsible fields.
    On page load the field value will be hidden and the labels will be shown as clickable links. Clicking them will expand the content of the field.
    I want to use field collections in the same way, but there give the maintainer the power to edit the 'label'. Adding fieldcollections of the form (title, content) should do that. On page load the title will be shown as a clickable link, and clicking on that will expand the content.

    For the collapsing functionality we use, as it is already there, ctools.

    1. make a field display collapsible with ctools
    In general using ctools it's very easy to make a field display collapsible.

    1.a Put this function in your template file
    function MyTheme_collapse_content($c_content, $collapse_heading) {
       print theme('ctools_collapsible', array('handle' => $collapse_heading, 'content' => $c_content, 'collapsed' => TRUE));
    }

    1.b  In the field template file simply put this code
    <?php
       $collapse_heading = $label;
       foreach ($items as $delta => $item): 
         $c_content.='<div class="field-item ';
         $c_content.=$delta % 2 ? 'odd' : 'even'; 
         $c_content.='"';
         $c_content.=' '. $item_attributes[$delta].'>';
         $c_content.= render($item).'</div>';
       endforeach;
      MyTheme_collapse_content($c_content, $collapse_heading);
    ?>

    1.b.1 template naming
    If you worry what to name the field template files simply check https://api.drupal.org/api/drupal/modules!field!field.module/function/theme_field/7


    Now, how to accomplish this task for the fieldcollections?

    2. Add a fieldcollection field to the contenttype
    In this example called Page or machinename field_event_sub_page
    2.1 Add two fields to the fieldcollection
    2.1.a text field page_title
    2.1.b  and a textarea page_text (filtered html)

    Now you can add field collections to the node consisting of a text field (page_title) and a textarea (page_text).
    Now I want these text fields  (the page_title) to show as links, and clicking on these links should open the corresponding textarea's (page_text), giving me a single ode behaving more or less like a book with only two levels.

    Using the ctools collapsing the problem is now reduced to getting the page_title and page_text field content in the $c_content and the $collapse_heading variables in a theme function like the above:

      MyTheme_collapse_content($c_content, $collapse_heading);

    This is usually a very annoying deconstruction of the fieldcollection instance, I must say I get lost a lot of times.
    But now I found this very elegant solution by Mike Minecki



    2.2  put these functions in your template.php

    function MyTheme_preprocess_field(&$vars, $hook) {
      $element = $vars['element'];
      if (isset($element['#field_name'])) {
        if ($element['#field_name'] == 'field_event_sub_page') {
        $vars['theme_hook_suggestions'][] = 'field__event_sub_page_collected';// waar is dit eigenlijk voor nodig

         $field_array = array('field_fesp_linktitle', 'field_fesp_text');//must match the fields you added to the field collection
        rows_from_field_collection($vars, 'field_event_sub_page', $field_array);
        }
      }
    }

    function rows_from_field_collection(&$vars, $field_name, $field_array) {
      $vars['rows'] = array();
      foreach($vars['element']['#items'] as $key => $item) {
        $entity_id = $item['value'];
        $entity = field_collection_item_load($entity_id);
        $wrapper = entity_metadata_wrapper('field_collection_item', $entity);
        $row = array();
        foreach($field_array as $field){
           $row[$field] = $wrapper->$field->value();
        }
        $vars['rows'][] = $row;
      }
     }


    2.2   Put this rendering in your fieldcollection template file
    In this example that would be the field--field_event_sub_page.tpl.php template file.
     <?php 
       foreach($rows as $row): 
          $collapse_heading $row['field_fesp_linktitle'];
          $c_content $row['field_fesp_text']['safe_value'];
          MyTheme_collapse_content($c_content, $collapse_heading);

       endforeach; ?>