Versione Drupal

Aggiunta di setting nella sezione del tema.

Inserimento di una nuova area nel settingdel tema. Creare il file theme-settings.php nella cartella del proprio tema.

 

Esempio: Inserimento e attivazione di una regione Testimonials del tema chiamato ARCADIA

<?php

function arcadia_form_system_theme_settings_alter(&$form, $form_state) {


    $form['settings'] = array(     
        '#type' => 'vertical_tabs',  
        '#title' => t('arcadia Settings'),
        '#prefix' => '<h2><small>' . t('Theme Settings') . '</small></h2>',
        '#weight' => 2,           
        '#collapsible' => TRUE,      
        '#collapsed' => FALSE,       
    );

...
...
...

    // Add a Testimonials Area.    
    $form['settings']['testimonials'] = array(
        '#type' => 'fieldset',
        '#title' => t('Testimonials Area Settings'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
    );

    $form['settings']['testimonials']['view_testimonial_area'] = array(
        '#type' => 'checkbox',
        '#title' => t('Display Testimonial Area'),
        '#default_value' => theme_get_setting('view_testimonial_area'),
        '#description' => t('Show testimonial area from the homepage.'),
    );
    
    $form['settings']['testimonials']['view_testimonial_photo'] = array(
        '#type' => 'checkbox',
        '#title' => t('Display Photo'),
        '#default_value' => theme_get_setting('view_testimonial_photo'),
        '#description' => t('Show testimonial photo in Block.'),
    );

}

 

 

una volta settati in Apperance -> NOME TEMA

la variabile è disponibile e può essere usata in tutti i file php del nostro tema quindi per abilitare la recione testimonials sulla nostra page.tpl.php vasterà inserire e controllare se la variabile (in questo caso una checkbox) è true o false

<?php if (!empty(theme_get_setting('view_testimonial_area'))): ?>
<div class="testimonials">
    <div class="container">
        <?php print render($page['testimonials']); ?>
    </div>
</div>
<?php endif; ?>

 

Stessa cosa se volessi disabilitare il campo photo in un blocco vista (Views: Testimonials - views-view-fields--testimonials--block.tpl.php)

<div class="item text-center">
<?php if (!empty(theme_get_setting('view_testimonial_photo'))): ?>
<h5 class="photo-testimonials"><?php print $fields['field_testimonial_photo']->content; ?></h5>
<?php endif; ?>

<h5 class="title"><?php print $fields['title']->content; ?></h5>
<div class="position"><?php print $fields['field_testimonial_position']->content; ?></div>
<?php print $fields['body']->content; ?></h5>
</div>