Hello,

I am writing a module, that creates node type. Node includes also a multiple media field. When I install my module node type is there, it has all created fields, but if I go to node edit form just media field is missing. Field itself is defined in another module, while instance is defined in module that creates node type. First module is dependency to second one. Here is my definition of field and it's instance:

<?php
//field definition
$fields['delo_title_image'] = array(
  'field_name' => 'delo_title_image',
  'type' => 'media', 
  'cardinality' => 0,
  'translatable' => TRUE,
  'settings' => array(),
);

//instance definition
  $instances['delo_title_image'] = array(
  'field_name' => 'delo_title_image',
  'label'       => $t("Title image(s)"),
  'description' => $t("Title image(s) for content. "),
  'required'    => true,
  'widget'      => array(
    'type'    => 'media_generic',
    'weight'     => 5,
  ),
  'display' => array(
    'default' => array(
      'label' => 'hidden',
      'type' => 'media_link',
      'weight'     => 5,
    ),
  ),
);

?>

Widget appears if I go to "Manage fields" page, open edit form for this field and save it. This does not fix the problem completely, since I get a fatal error when trying to preview created node.


PHP Fatal error: Cannot use object of type stdClass as array in /var/www/modules/field/field.form.inc on line 193, referer: http://polet.anna.delo.si/node/add/article?render=overlay&render=overlay

Can you tell me what am I doing wrong?

Comments

rogueturnip’s picture

I'm in the same boat. Would like to know how to do this. Maybe a list of the different display types and widget types might help too.

THanks!

slashrsm’s picture

I was also playing with different configuration and settings... but no success.

bryancasler’s picture

Subscribe, my blog entry page now permanently displays the error Inactive fields are not shown unless their providing modules are enabled. The following fields are not enabled:media (field_media) field requires the media_generic widget provided by media module

I even uninstalled the media module, the error is still persisting.

AgaPe’s picture

got my issue solved by updating the `field_config` database table,
set 'module' to your field module if its wrong (for me image was somehow change to audiofield) and 'active' to 1

bryancasler’s picture

AgaPe could you tell in more detail how I could resolve this. Heads up, I'm not familiar with working directly in the DB.

AgaPe’s picture

Do you have access to phpmyadmin or sth like that? then its just clicking the right table, edit the right row

bryancasler’s picture

I have access to phpmyadmin, will give this a look

bryancasler’s picture

Should I just delete this row?

http://awesomescreenshot.com/0bd7odh52

AgaPe’s picture

no no do not delete it :) at the begining of the line you have the edit button (a pencil or sth like that), click it and edit the field "active" from 0 to 1

bryancasler’s picture

Thanks, I made that one change and I got the following error when looking at the node's "Manage Fields" page.

Notice: Undefined index: module in _field_info_prepare_instance_widget() (line 385 of C:\xampp\htdocs\drupal\modules\field\field.info.inc).
Notice: Undefined index: module in _field_info_prepare_instance_display() (line 353 of C:\xampp\htdocs\drupal\modules\field\field.info.inc).
Notice: Undefined index: media in field_ui_field_overview_form() (line 355 of C:\xampp\htdocs\drupal\modules\field_ui\field_ui.admin.inc).
Notice: Undefined index: in field_ui_field_overview_form() (line 361 of C:\xampp\htdocs\drupal\modules\field_ui\field_ui.admin.inc).

I then thought maybe I should try re-enabling the media module before doing this. So I reset the value back to 0 and enabled the Media module.

Then the following error was spit out while the module was being enabled

FieldException: Attempt to create an instance of field file on bundle default that already has an instance of that field. in field_create_instance() (line 488 of C:\xampp\htdocs\drupal\modules\field\field.crud.inc).

The media module looked to have been successfully enabled so I went back into PHPMyAdmin and changed the value back to 1.

Now I get no errors! Thanks for everything.

AgaPe’s picture

Good its solved. :)

bennash’s picture

I had the same problem, after downgrading and then upgrading the media module. The fix suggested above worked great for me too. Thanks.

JacobSingh’s picture

dave reid’s picture

Status: Active » Closed (cannot reproduce)
pehohlva@gmail.com’s picture

I use the GIT media module & Drupal 7.17
I having successful create media field on my migrate typo3 module

but if I migrate 10 image to this field ('cardinality' => 10,) only first (first on array list) item is visible and 10 item go to media browser on dir
& i must select from media browser by hand...

<?php

 /// ....  chain from typo3 field to reformat ...

   $xscheme['field_tv_cat']['name'] = 'field_tv_cat';
    $xscheme['field_tv_cat']['type'] = 'taxonomy_term_reference';
    $xscheme['field_tv_cat']['instance'] = array(
        'entity_type' => 'node',
        'bundle' => TI_FORMANAME,
        'module' => 'taxonomy',
        'cardinality' => 1,
        'deleted' => 0,
        'locked' => 0,
        'label' => 'Associazione Categoria',
        'description' => 'Seleziona dalla lista',
        'required' => TRUE,
        'widget' => array('type' => 'options_select'),
        'settings' => array(
            'allowed_values' => array('vocabulary' => 'categorie', 'parent' => 0),
        ),
        'display' => array('default' => array('label' => 'hidden')));


  $xscheme['field_pics_media']['name'] = 'field_pics_media';
    $xscheme['field_pics_media']['type'] = 'media';
    $xscheme['field_pics_media']['instance'] = array(
        'entity_type' => 'node',
        'bundle' => TI_FORMANAME,  // machine_name here
        'module' => 'mediafield',
        'cardinality' => 10,
        'active' => 1,
        'locked' => 0,
        'label' => 'Immagini Multiple',
        'description' => 'Image Gallery',
        'required' => FALSE,
        'settings' => array('image_style' => 'piccolo_160'),
        'widget' => array('type' => 'media_generic'),
        'display' => array('default' => array('label' => 'hidden')));
     // new image style Implementation of hook_image_default_styles().


    foreach ($xscheme as $item) {
        $x = (object) $item;
        // field create 
        $field = array(
            'field_name' => $x->name,
            'type' => $x->type,
        );
        error_log('Loop on ->' . $x->name);
        $instance = $x->instance;
        $instance['field_name'] = $x->name;
        // Check that the field type is known.
        //$field_type = field_info_field_types($field['type']);
        //if (!$field_type) {
        ///throw new FieldException(t('Attempt to create a field of unknown type %type.', array('%type' => $field['type'])));
        ///}
        if (!field_info_field($x->name)) {
            error_log('Make ->' . $x->name);
            field_create_field($field);
            field_create_instance($instance);
            drupal_set_message('<p>Installazione di content_type:' . TI_FORMANAME . '  ->' . $x->name . '</p>');
        } else {
            error_log('Exist! mistake field?? ! on ->' . $x->name);
        }
    }
?>