Community

Image upload and text with summary field + some field_schema

Sup, Drupal community!

I have some issues regarding a custom made module. The module is supposed to create a custom field type that can be added in content types later. What I basically want to do is to create a fieldset that holds a title field, description field, link(embed) field and a thumbnail upload field.

First of all, I am having trouble understanding something in hook_schema. Here is mine for this module:

<?php
function essential_field_schema($field) {

    if (
$field['type'] == 'essential') {

       
$schema['columns']['name'] = array(
           
'type' => 'varchar',
           
'length' => '255',
           
'not null' => FALSE,
        );
       
$schema['columns']['description'] = array(
           
'type' => 'varchar',
           
'length' => '2100',
           
'not null' => FALSE,
        );
       
$schema['columns']['thumbnail'] = array(
           
'type' => 'varchar',
           
'length' => '255',
           
'not_null' => FALSE,
        );
       
$schema['columns']['link'] = array(
           
'type' => 'varchar',
           
'length' => '2100',
           
'not null' => FALSE,
        );
       
$schema['indexes'] = array(
           
'name' => array('name'),
           
'description' => array('description'),
           
'thumbnail' => array('thumbnail'),
           
'link' => array('link'),
        );

        return
$schema;
    }
}
?>

The issue I get is that I can not define the description and the thumbnail as a longtext, although I am aware of http://drupal.org/node/159605

The second issue I get is when getting the thumbnail widget format and display on the page. Here is the code from implementing hook_field_widget_form():

<?php
        $element
['thumbnail'] = array(
           
'#type' => 'managed_file',
           
'#description' => t('Thumbnail image.'),
           
'#upload_location' => 'public://essential_thumbnail/',
           
'#title' => t('Thumbnail'),
           
'#default_value' => isset($items[$delta]['thumbnail']) ? $items[$delta]['thumbnail'] : NULL,
        );
?>

It uploads the image just fine and saves it just fine. I've notice that it saves in the database field as a number (ex: 485). I have no idea what that number represents so if someone could point me some documentation it would be swell. The problem is that I don't know how to display it. I've defined a special theme format for it:
<?php
function essential_theme($existing, $type, $theme, $path) {
    return array(
       
'essential_formatter_default' => array(
           
'variables' => array('item' => NULL),
        ),
    );
}


function
theme_essential_formatter_default($item) {
   
   
$output = '';
   
$output .= '<div class="essential-wrapper">';
   
$output .=  $item['name'] . "<br>";
   
$output .=  $item['description'] . "<br>";
   
$output .=  $item['thumbnail'] . "<br>";
   
$output .=  $item['link'];
   
$output .= '</div><br />';

    return
$output;
}
?>

The issue is that I don't know what to do with that stored number in the database in order to render the image to display in the width and height I want or for that matter, just display. Again, if someone could point me some docs it would be more than swell.

Also there are some questions that I want to ask. Is there any way I can add a delete field button like in the screenshot below? Is there like any module that does that?
Only local images are allowed.

Nevertheless I have one more question which is a bit more offtopic. What was that php snippet that when executed into drupal devel php function it returned the field settings which was very useful when creating programmatically a custom content type?

Thank's in advance,
Dragos Rizescu

Comments

Update

I fixed the hook_schema issue. I was indexing the description and link fields when declaring them as a longtext (type => text, size => big) into the schema, and these caused a mysql error, so one problem solved.
Also, I couldn't show the screenshot in an img tag for some drupal securities issues, however here's the direct link of the screenshot:
http://cdn.imghack.se/images/0bf52ef7d769183993690a77077e550f.jpg