User login

Gathering the data needed to abuse field formatters-- disable and combine and change per node settings set by user

For old times sake... this is one of the last outputs like this before I use a properly integrated development environment, Eclipse PDT (for PHP) with xdebug, which will show all the variables without the Drupal set messaging and such.

Field_placement displaying using CCK field formatters

This is the point where after more blocks and bloopers than I care to admit that we should finally have all the data we need.

Before I try to output any of it though.

The below function produces the below drupal_set_message (dsm using devel) output:

<?php
/**
* Pseudo-implementation of hook_field_formatter().
*
* Modeled on text_field_formatter() in CCK's text.module.
*
* The $node argument is necessary so that filter access can be checked on
* node preview.
*/
function field_placement_field_formatter_text($field, $item, $placement_formatter, $node) {
  $formatter = substr($placement_formatter, 0, 15);
  if (!isset($item['value'])) {
    $text = '';
  }

  if ($allowed_values = text_allowed_values($field)) {
    $text = $allowed_values[$item['value']];
  }

  switch ($formatter) {
    case 'plain':
      $text = strip_tags($item['value']);
      break;

    case 'trimmed':
      $text = node_teaser($item['value'], $field['text_processing'] ? $item['format'] : NULL);
      break;

    case 'default':
      $text = $item['value'];
  }

  if ($field['text_processing']) {
    $text = check_markup($text, $item['format'], is_null($node) || isset($node->in_preview));
  }
  else {
    $text = check_plain($text);
  }

  // above was pretty much stolen directly from text_field_formatter().
  // Now we add the image.
  // @TODO
  // all this only works right if there is only one placement-enabled field
  // per node.  We need to add a txt column to {field_placement} and change all
  // of this to do it right  :-/
  $delta = 0;
dsm($node->nid);
dsm($field['field_name']);
// field name so hard to get because $item means something totally different for text CCK fields as it does for image CCK fields-- it provides no nid, so we'll get that from the node object instead
// AND the Field name has to be gotten from the {field_placement_txt_field} table!
  $cck_field = field_placement_txt_field_get_cck($node->type, $field['field_name']);
  $fpd = field_placement_load($node->nid, $cck_field);
dsm($fpd);
  // not needed
//  $region = field_placement_region($fpd[$delta]['regionid']);
  $regionid = $fpd[$delta]['regionid'];
  $classes = array();
  $field_first = FALSE;
  if ($regionid == 1 || $regionid == 2) {  // top
    $classes[] = 'field-placement-top';
    $field_first = TRUE;
  }
  if ($regionid == 3 || $regionid == 4) {  // bottom
    $classes[] = 'field-placement-bottom';
  }
  if ($regionid == 1 || $regionid == 4) {  // left
    $classes[] = 'field-placement-left';
  }
  if ($regionid == 2 || $regionid == 3) {  // right
    $classes[] = 'field-placement-right';
  }

  // @TODO: remove all I know isn't used anyway?
  $cck_field = array (
    'field_name' => $fpd[$delta]['cck'],
    'type' => 'image',
    'required' => '0',
    'multiple' => '1',
    'db_storage' => '0',
    'widget' =>
    array (
      'max_resolution' => '0',
      'image_path' => 'product_images',  // issue
      'custom_alt' => 0,
      'custom_title' => 0,
      'teaser_preset' => NULL,
      'body_preset' => NULL,
      'type' => 'image',
      'weight' => '-1',
      'label' => 'Image',
      'description' => '',
    ),
    'type_name' => $item['type_name'],
    'display_settings' =>
    array (
      'label' =>
      array (
        'format' => 'hidden',
      ),
      'teaser' =>
      array (
        'format' => 'place_field_image',
      ),
      'full' =>
      array (
        'format' => 'place_field_image',
      ),
    ),
  );
dsm($fpd);
dsm('field_name');
$field_name = $fpd[$delta]['cck'];
dsm($field_name);
//  $cck_item = $node->{$fpd[$delta]['cck']};
dsm($cck_field);
//  dsm($cck_item);
  array (
  'fid' => '102',
  'title' => 'headerbg.png',
  'alt' => 'headerbg.png',
  'nid' => '160',
  'filename' => 'headerbg.png',
  'filepath' => 'sites/default/files/product_images/headerbg.png',
  'filemime' => 'image/png',
  'filesize' => '5196',
);

dsm($node);

  $field = '<div class="'. implode(' ', $classes) .'">';

//  $field .= field_placement_field_formatter($cck_field, $cck_item, $cck_formatter);
}
?>

  • field_placement_image_linked
  • field_placement_text_default
  • 216
  • field_featured_product_desc
  • field_placement_image_linked
  • field_placement_text_default
  • 216
  • field_featured_product_desc
  • Array
    (
    [0] => Array
    (
    [nid] => 216
    [cck] => field_product_image
    [delta] => 0
    [regionid] => 1
    [presetid] => 12
    )

    )

  • Array
    (
    [0] => Array
    (
    [nid] => 216
    [cck] => field_product_image
    [delta] => 0
    [regionid] => 1
    [presetid] => 12
    )

    )

  • field_name
  • field_product_image
  • Array
    (
    [field_name] => field_product_image
    [type] => image
    [required] => 0
    [multiple] => 1
    [db_storage] => 0
    [widget] => Array
    (
    [max_resolution] => 0
    [image_path] => product_images
    [custom_alt] => 0
    [custom_title] => 0
    [teaser_preset] =>
    [body_preset] =>
    [type] => image
    [weight] => -1
    [label] => Image
    [description] =>
    )

    [type_name] =>
    [display_settings] => Array
    (
    [label] => Array
    (
    [format] => hidden
    )

    [teaser] => Array
    (
    [format] => place_field_image
    )

    [full] => Array
    (
    [format] => place_field_image
    )

    )

    )

  • stdClass Object
    (
    [nid] => 216
    [vid] => 236
    [type] => featured_product
    [status] => 1
    [created] => 1217254020
    [changed] => 1217296141
    [comment] => 0
    [promote] => 0
    [sticky] => 0
    [revision_timestamp] => 1217296141
    [title] => I win
    [body] =>
    [teaser] =>
    [log] =>
    [format] => 0
    [uid] => 1
    [name] => submin
    [picture] =>
    [data] => a:0:{}
    [path] => content/i-win
    [last_comment_timestamp] => 1217254020
    [last_comment_name] =>
    [comment_count] => 0
    [taxonomy] => Array
    (
    )

    [files] => Array
    (
    )

    [field_product_image] => Array
    (
    [0] => Array
    (
    [fid] => 157
    [title] => drupalgeonames.jpg
    [alt] =>
    [nid] => 216
    [filename] => drupalgeonames.jpg
    [filepath] => sites/default/files/product_images/drupalgeonames_12.jpg
    [filemime] => image/jpeg
    [filesize] => 67667
    [view] =>
    )

    )

    [field_featured_product_desc] => Array
    (
    [0] => Array
    (
    [value] => win win win
    [format] => 1
    )

    )

    [readmore] =>
    [content] => Array
    (
    [body] => Array
    (
    [#value] =>
    [#weight] => 0
    )

    )

    )

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.