php - Drupal Field API - Settings List -
i'm trying create 'link_field' in drupal through module, i've got following code i'd configure field settings following:
- not require title
- update number of values unlimited
i'm struggling find information around setting key/pair values can pass through these, able offer guidance on these?
<?php /** * implements hook_enable(). * * create field. fields can created without needs attach them * entities. */ function youtube_carousel_enable() { $field = array( 'field_name' => 'ytcarousel_field', 'type' => 'link_field', ); field_create_field($field); /** * bind field entity bundle. */ $instance = array( 'field_name' => $field['field_name'], 'entity_type' => 'node', 'bundle' => 'homepage', 'label' => 'youtube video' ); field_create_instance($instance); } /** * implements hook_disable(). * * remove field node bundle (content type) , delete field. */ function youtube_carousel_disable() { $instance = array( 'field_name' => 'ytcarousel_field', 'entity_type' => 'node', 'bundle' => 'homepage', 'label' => 'youtube video' ); field_delete_instance($instance); field_delete_field($instance['field_name']); print 'removed ' . $instance['field_name'] . "\n"; } ?> cheers
after viewing html source key/value pairs i've managed similar above following code:
<?php /** * implements hook_enable(). * * create field. fields can created without needs attach them * entities. */ function youtube_carousel_enable() { $field = array( 'field_name' => 'ytcarousel_field', 'type' => 'link_field', 'cardinality' => -1 ); field_create_field($field); /** * bind field entity bundle. */ $instance = array( 'field_name' => $field['field_name'], 'entity_type' => 'node', 'bundle' => 'homepage', 'label' => 'youtube video', 'settings' => array('title' => 'required') ); field_create_instance($instance); } /** * implements hook_disable(). * * remove field node bundle (content type) , delete field. */ function youtube_carousel_disable() { $instance = array( 'field_name' => 'ytcarousel_field', 'entity_type' => 'node', 'bundle' => 'homepage', 'label' => 'youtube video', 'settings' => array('title' => 'required') ); field_delete_instance($instance); field_delete_field($instance['field_name']); print 'removed ' . $instance['field_name'] . "\n"; } ?> the cardinality controls have many instances value can have, "-1" unlimited.
'cardinality' => -1 the title attribute controlled via instance not field itself, believe, , uses text based values rather numeric.
'settings' => array('title' => 'required')
Comments
Post a Comment