View fields from the same database column - drupal

So, I have serialized data within the uc_orders table. This data has several parameters of interest each of which I want to create a unique field from.
Each one of these $data values work on their own. Obviously I am rewriting the value on the second declaration. How can I reference the same data location twice so that both of the fields can be used and I can explode all of my serialized data into separate fields?
function uc_order_views_data() {
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Arrival Date'),
'help' => t('Arrival date choosen by customer during checkout.'),
'field' => array(
'handler' =>'uc_order_handler_field_arrive_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Ship Date'),
'help' => t('The date to ship the order by.'),
'field' => array(
'handler' =>'uc_order_handler_field_ship_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
}

I finally found the answer.
$data['uc_orders']['data2'] = array(
'group' => t('Order') . ':data',
'title' => t('Arrival Date'),
'real field' => 'data',
'help' => t('Arrival date choosen by customer during checkout.'),
'field' => array(
'handler' =>'uc_order_handler_field_arrive_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
$data['uc_orders']['data'] = array(
'group' => t('Order') . ':data',
'title' => t('Ship Date'),
'help' => t('The date to ship the order.'),
'field' => array(
'handler' =>'uc_order_handler_field_ship_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
);
The solution is to add 'real field' => 'field name', and change the $data id.

Related

How to clear selected values from multiple select field

I have a form with a multiple select field where a user can select several values in it
$form['export_type_section']['export_type'] = array(
'#title' => t('Export types'),
'#type' => 'select',
'#multiple' => TRUE,
'#size' => 10,
'#options' => $options,
'#ajax' => array(
'event' => 'change',
'callback' => 'test_export_form_export_type_ajax_callback',
),
);
I have another field in the form
$form['document_type'] = array(
'#type' => 'select',
'#options' => array(0 => t('All Types'), 1 => t('Test1'), 2 => t('Test2'), 3 => t('Test3')),
'#title' => 'Document Types',
'#default' => 0,
'#ajax' => array(
'event' => 'change',
'callback' => 'test_export_form_document_type_ajax_callback',
),
);
I am trying to figure out how to reset the export_type field when the document_type is changed. I would like to clear the selected values so that the user can reselect what is needed whenever the document_type changes. I tried several formats in the test_export_form_document_type_ajax_callback but none worked.
Anybody knows how to do it?

Wordpress - Trying to display date from custom form two different ways

I am trying to create an events page in Wordpress. I am using the Advanced Custom Fields plugin to generate my forms. I would like to style the month and year differently from the day in the listing section. However, I don't want to make the user have to input the same date twice in the back-end just for this. Is there a way to display the content from the one form in two different calibrations on the front-end? For example, can I display it once as month and year then once again as just the day? Is there any other workaround? Any advice would be appreciated.
Here is my custom form code:
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_5fec83c0a2f7b',
'title' => 'Event Particulars',
'fields' => array(
array(
'key' => 'field_5fec83ca0dc8b',
'label' => 'Date of event',
'name' => 'date_of_event',
'type' => 'date_picker',
'instructions' => '',
'required' => 0,
'conditional_logic' => array(
array(
array(
'field' => 'field_5fec84a00dc8c',
'operator' => '!=empty',
),
),
),
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'display_format' => 'Y F j',
'return_format' => 'Y F j',
'first_day' => 1,
),
array(
'key' => 'field_5fec84a00dc8c',
'label' => '',
'name' => '',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array(
array(
array(
'param' => 'page_type',
'operator' => '==',
'value' => 'front_page',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => true,
'description' => '',
));
endif;
You can load the value of the date field, create a date object and then format that date object as you prefer:
// Load field value.
$date_string = get_field('date_of_event');
// Create DateTime object from value.
// Here you must use the format that you specified as the "return format" of the date field in ACF.
$date = DateTime::createFromFormat('Y F j', $date_string);
// Now you can use the date object to print the date in different formats:
echo $date->format('M Y');
echo $date->format('j M Y');
Have a look at the "Modifiy value" section of the docs:
https://www.advancedcustomfields.com/resources/date-picker/

create custom content type with custom table fields in drupal 7

I want to create a module in which, when I install that module, it should create custom table defined in homepage_blocks_schema(), create content-type defined in homepage_blocks_install() and in that content type, create custom fields same as my schema.
Here is function,
function homepage_blocks_schema() {
$schema['homepage_blocks'] = array(
'fields' => array(
'hid' => array(
'type' => 'int',
'length' => 11,
'unsigned' => TRUE,
'not null' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 255,
),
'image' => array(
'type' => 'varchar',
'length' => 255,
),
),
'primary key' => array('hid'),
);
return $schema;
}
homepage_blocks_install() {
$homepage_blocks = array(
'type' => 'homepage_blocks',
'name' => $t('Homepage Blocks'),
//'base' => 'node_content',
'base' => 'homepage_blocks',
'custom' => true,
'modified' => true,
'locked' => false,
'title_label' => $t('Homepage Blocks')
);
$content_type = node_type_set_defaults($homepage_blocks);
//node_add_body_field($content_type, 'Body'); // add the body field to the content type
node_type_save($content_type); // create the content type
variable_set('node_options_homepage_blocks', array('status'));
variable_set('comment_homepage_blocks', 'COMMENT_NODE_HIDDEN'); // hide comments for this node.
variable_set('node_submitted_homepage_blocks', false); // Hide date and author information
//drupal_install_schema('homepage_blocks');
foreach (_homepage_blocks_installed_fields() as $field) { // Create all the fields we are adding to our content type.
//krumo(field_create_field($field));
field_create_field($field);
}
foreach (_homepage_blocks_installed_instances() as $instance) { // Create all the instances for our fields.
$instance['entity_type'] = 'node';
$instance['bundle'] = 'homepage_blocks';
field_create_instance($instance);
}
}
function _homepage_blocks_installed_fields() {
$t = get_t();
$fields = array(
'hmblock_title' => array(
'field_name' => 'hmblock_title',
'label' => $t('Title'),
//'cardinality' => 1,
'type' => 'text',
'settings' => array(
'max_length' => 255,
),
),
'hmblock_image' => array(
'field_name' => 'hmblock_image',
'label' => $t('Image'),
//'cardinality' => 1,
'type' => 'image',
'settings' => array(
'default_image' => 0,
'uri_scheme' => 'public',
),
),
);
//$fields = drupal_get_schema('homepage_blocks');
return $fields;
}
function _homepage_blocks_installed_instances() {
$t = get_t();
$instances = array(
'hmblock_title' => array(
'field_name' => 'hmblock_title',
'label' => $t('Title'),
'cardinality' => 1,
'widget' => array(
'type' => 'text_textfield',
'settings' => array('size' => 255),
),
),
'hmblock_image' => array(
'field_name' => 'hmblock_image',
'label' => $t('Image'),
'cardinality' => 1,
'type' => 'image',
'settings' => array(
'alt_field' => 1,
'file_directory' => 'image',
'file_extensions' => 'png gif jpg jpeg',
'max_filesize' => '50mb',
'max_resolution' => '',
'min_resolution' => '',
'title_field' => 1,
'user_register_form' => FALSE,
),
'widget' => array(
'settings' => array(
'preview_image_style' => 'thumbnail',
'progress_indicator' => 'throbber',
),
)
),
);
return $instances;
}
This code creates table and content type but not its fields..
Can anyone help ?
There is an easier way
you can create your custom type using drupal core and fields module and then export it into a module using Features module.
You can find a full guide here : Bundling site settings using Features

Adding a value to a textbox generated on Symfony 2

Having this:
echo $view['form'] -> row($form["codelist"], array(
//widget
"widgetArgs" => array(
"attr" => array(
'class' => 'input-xlarge tooltipRight',
'id' => "gift_codelist"
),
"tooltip"=>"gift.tooltip.codelist",
"translation_domain" =>"brand"
),
"labelArgs" => array(
"label_attr" => array(
'class' => 'control-label',
)) ,"rowType"=>2
)
);
How do you add an initial value to that textbox?
If you want to add an actual value to the field, you can use the value attribute:
"attr" => array(
'class' => 'input-xlarge tooltipRight',
'id' => "gift_codelist",
'value' => "Your initial value"
)
But if you are using HTML5 and just want to give a hint to your users, you'd better use a placeholder:
"attr" => array(
'class' => 'input-xlarge tooltipRight',
'id' => "gift_codelist",
'placeholder' => "Your initial value"
)
http://www.w3.org/html/wg/drafts/html/master/forms.html#the-placeholder-attribute

Add allowed values list programmatically in drupal 7 CCK field "list_text"

I was wondering if i can create programmatically a CCK field instance and insert the "allowed_values" in a single stage. So i tried this:
field_create_instance(array(
'field_name' => 'card number',
'entity_type' => 'payment_method',
'bundle' => 'debit_card',
'label' => t('Debit/Credit card'),
'description' => t('Add card\'s number '),
'widget' => array(
'type' => 'options_select',
'weight' => 0,
'settings' => array('size' => 50),
),
'required' => TRUE,
));
I've tried some case i.e to set in 'setting' => array( 'allowed_values' => array( 1, 2, 3 ) ) but nothing happened. Any suggestions?
Solution:
function MY_MODULE_install() {
field_create_field(array(
'field_name' => 'months',
'type' => 'list_text',
'cardinality' => 1,
'settings' => array('allowed_values_function' => 'get_months'),
'entity_types' => array('user', 'node'),
));
}
function get_months() {
$months = array( '01', '02', '03',...'12');
return $months;
}
Warning: Callback function must always be in *.module file of your custom module.

Resources