home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (text.devel_generate.inc)

This example Drupal source code file (text.devel_generate.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, bundle, devel_create_content, else, empty, field, format, formats, function, if, instance, object, php, return

The text.devel_generate.inc Drupal example source code

<?php
// $Id: text.devel_generate.inc,v 1.2 2010/03/16 04:42:45 weitzman Exp $

function text_devel_generate($object, $field, $instance, $bundle) {
  if (field_behaviors_widget('multiple values', $instance) == FIELD_BEHAVIOR_CUSTOM) {
    return devel_generate_multiple('_text_devel_generate', $object, $field, $instance, $bundle);
  }
  else {
    return _text_devel_generate($object, $field, $instance, $bundle);
  }
}

function _text_devel_generate($object, $field, $instance, $bundle) {
  $object_field = array();
  if (!empty($instance['settings']['text_processing'])) {
    $formats = filter_formats();
    $format = array_rand($formats);
  }
  else {
    $format = filter_fallback_format();
  }

  if ($instance['widget']['type'] != 'text_textfield') {
    // Textarea handling
    $object_field['value'] = devel_create_content($format);
    if ($instance['widget']['type'] == 'text_textarea_with_summary' && !empty($instance['display_summary'])) {
      $object_field['summary'] = devel_create_content($format);
    }
  }
  else {
    // Textfield handling.
    // Generate a value that respects max_length.
    if (empty($field['settings']['max_length'])) {
      $field['settings']['max_length'] = 12;
    }
    $object_field['value'] = user_password($field['settings']['max_length']);
  }
  $object_field['format'] = $format;
  return $object_field;
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal text.devel_generate.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.