Hi all, i'm trying to create my own layout, in the documentation there's written "See Layouter Extension Example module for details (you'll find it in modules/layouter_extension_example sub-directory)." but i can't find it.
Is there a place where to find this example? Thanks!

Comments

francescoq’s picture

Hi, i've done in this way:

I've implemented those hooks:

hook_layouter_templates().
hook_theme().
hook_form_FORM_ID_alter().

and the two functions for the form and the form submit.

Then i've created the css to show the thumbnail of the template
and the tpl.php file to show my layout...

It seems everything ok to me...

/**
 * Implements hook_layouter_templates().
 */
function MYMODULE_layouter_templates() {
  $items = array(
    'two_columns_img_text' => array(
      'title' => t('Two colums with images.'),
      'form' => 'MYMODULE_two_columns_img_text_form',
      'theme' => 'MYMODULE_two_columns_img_text',
    ),
  );
  return $items;
}

/**
 * Returns Form for adding content for two_columns_img_text layout.
 */
function MYMODULE_two_columns_img_text_form($form, &$form_state) {
  $form_state['title'] = $form_state['form_info']['forms'][$form_state['step']]['form title'];
  $form['left'] = array(
    '#type' => 'fieldset',
    '#tree' => 1,
    '#title' => t('Left'),
  );
  $form['left']['text_content_left'] = layouter_text_content();
  $form['left']['image'] = layouter_image_content();
  $form['left']['image_style'] = layouter_image_style();
  $form['right'] = array(
    '#type' => 'fieldset',
    '#tree' => 1,
    '#title' => t('Right'),
  );
  $form['right']['text_content_right'] = layouter_text_content();
  $form['right']['image'] = layouter_image_content();
  $form['right']['image_style'] = layouter_image_style();

  return $form;
}

/**
 * Proccess Layouter Form with two_columns_img_text.
 */
function MYMODULE_two_columns_img_text_form_submit($form, &$form_state) {
  $values = $form_state['values'];

  //Left
  $text_left = strip_tags($values['left']['text_content_left']);
  $image_left_fid = $values['left']['image'];
  $image_left_style = $values['left']['image_style'];
  $image_left_file = file_load($image_left_fid);
  $image_left_file->status = FILE_STATUS_PERMANENT;
  file_save($image_left_file);
  $style_left_theme = ($image_left_style == 'layouter_none') ? 'image' : 'image_style';
  $image_left = theme($style_left_theme, array('style_name' => $image_left_style, 'path' => $image_left_file->uri));

  //Right
  $text_right = strip_tags($values['right']['text_content_right']);
  $image_right_fid = $values['right']['image'];
  $image_right_style = $values['right']['image_style'];
  $image_right_file = file_load($image_right_fid);
  $image_right_file->status = FILE_STATUS_PERMANENT;
  file_save($image_right_file);
  $style_right_theme = ($image_right_style == 'layouter_none') ? 'image' : 'image_style';
  $image_right = theme($style_right_theme, array('style_name' => $image_right_style, 'path' => $image_right_file->uri));

  $textarea_id = $form_state['textarea_id'];

  $attributes_array = array(
    'text_left' => $text_left,
    'image_left' => $image_left,
    'text_right' => $text_right,
    'image_right' => $image_right,
  );

  // Apply the layout to the content.
  $content = theme('MYMODULE_two_columns_img_text', $attributes_array);
  // Insert it into textarea field.
  layouter_insert_content_into_textarea($textarea_id, $content);
}

/**
 * Implements hook_theme().
 */
function MYMODULE_theme($existing, $type, $theme, $path) {
  return array(
    'MYMODULE_two_columns_img_text' => array(
      'variables' => array(
        'left' => NULL,
        'right' => NULL,
      ),
      'template' => 'layouter/tpl/two_columns_img_text',
    ),
  );
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function MYMODULE_form_layouter_choose_layout_form_alter(&$form, &$form_state, $form_id) {
  $module_path = drupal_get_path('module', 'MYMODULE');
  $form['#attached']['css'] = array($module_path . '/layouter/enrocca_layouter.css');
}

  • Maxilver committed 3b79e48 on 7.x-1.x
    Issue #2487395 by FrancescoQ: Create own layout
    
adci_contributor’s picture

Status: Active » Fixed

Hello Francesco! Thank you for your feedback.

It seems Example Module was lost accidentally. We've restored it back at the 7.x-1.7 release.
Thanks again for your attentiveness.

// Your way to create own layout is great. I'm really glad to see, that our hooks is used by other members of Drupal Community.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.