I'm trying to create my first TYPO3 extension, with backend list records.
Now I can register my own list records, but they are registert under tt_news like this:
News
News
News cat
Inventory
Of course I want to make my extension have it's own parent category like tt_news has.
News
News
News cat
Inventoy
inventory item
Does anybody have experience with this?
My ext_tables.php so far:
<?php
if (!defined ('TYPO3_MODE')) die ('Access denied.');
$TCA['tx_inventory_domain_model_product'] = array (
'ctrl' => array (
'title' => 'Inventory',
'label' => 'name',
),
'columns' => array(
'name' => array(
'label' => 'Item Label',
'config' => array(
'type' => 'input',
'size' => '20',
'eval' => 'trim,required'
)
),
'description' => array(
'label' => 'Item Description',
'config' => array(
'type' => 'text',
'eval' => 'trim'
)
),
'quantity' => array(
'label' => 'Stock Quantity',
'config' => array(
'type' => 'input',
'size' => '4',
'eval'=> 'int'
)
),
),
'types' => array(
'0' => array('showitem' => 'name, description, quantity')
)
);
?>
Related
I am using the ACF plugin in one of the WordPress websites and I have the following configuration for a user dropdown. This is added as a PHP code.
acf_add_local_field_group(array (
'key' => 'group_557ad1ef2b8a1',
'title' => 'Authors',
'fields' => array (
array (
'key' => 'field_557ad24ba99e5',
'label' => 'Featured',
'name' => 'featured_authors',
'type' => 'repeater',
'instructions' => 'Choose a maximum of 6 authors',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'min' => '',
'max' => 6,
'layout' => 'table',
'button_label' => 'Add Author',
'sub_fields' => array (
array (
'key' => 'field_5582bc82f8419',
'label' => 'Author',
'name' => 'featured_authors_author',
'type' => 'user',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'role' => '',
'allow_null' => 0,
'multiple' => 0,
),
),
)
'menu_order' => 0,
'position' => 'normal',
'style' => 'seamless',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => array (
0 => 'the_content',
1 => 'author',
2 => 'featured_image',
),
));
Now from the admin section, I am trying to add this field to the page, but it is not permitting the admin to select users. The dropdown is showing without any values. I am using the following versions:
Wordpress - 5.7.3
Advanced Custom Fields - 5.4.5
You have a syntax error in your code. You didn't close the first array() inside the 'fields' parameter in your main list of fields. Before this line:
'menu_order' => 0,
you need to add this:
),
This will close the 'fields' parameter, and allow it to process the parameters that appear after it.
I ended up recreating your field group in the ACF User Interface in the WP Admin, then exported the php, stripped out all the unnecessary/default parameters, and it's working great for me on a test environment. See the code below. I stripped out all of the settings that were just set to the default settings, to help make things a bit more readable.
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_6148d6a5d8172',
'title' => 'Authors',
'fields' => array(
array(
'key' => 'field_6148d6afde7ec',
'label' => 'Featured',
'name' => 'featured_authors',
'type' => 'repeater',
'instructions' => 'Choose a maximum of 6 authors',
'max' => 6,
'button_label' => 'Add Author',
'sub_fields' => array(
array(
'key' => 'field_6148d6d5de7ed',
'label' => 'Author',
'name' => 'featured_authors_author',
'type' => 'user',
'required' => 1,
),
),
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'post',
),
),
),
'style' => 'seamless',
'hide_on_screen' => array(
0 => 'the_content',
1 => 'author',
2 => 'featured_image',
),
));
endif;
One thing I noticed is that your code doesn't have any Location settings to dictate what post type or other element the field group should appear on, so I set my example to appear on every Post. You may need to adjust this to match your needs.
I also included the if function_exists conditional wrapper so that if you turn off the ACF plugin, it won't generate errors when it cannot find the acf_add_local_field_group() function.
I would like to ask for help, I am currently learning the WordPress customizer and iplementing it on my project. I have a select field which I would like to increment and decrement on button click (+/-).
$wp_customize->add_section('samplecustom_section' , array(
'title' => esc_html__('Sample Customizer', 'theme_name'),
'priority' => 169,
'capability' => 'edit_theme_options',
));
$wp_customize->add_setting('sample-list', array(
'default' => '',
'transport' => 'refresh',
));
$wp_customize->add_control('sample-list', array(
'label' => esc_html__('Sample Label', 'theme_name'),
'description' => esc_html__('Sample description', 'theme_name'),
'section' => 'samplecustom_section',
'settings' => 'sample-list',
'type' => 'select',
'choices' => array(
'value1' => __( 'Value 1' ),
'value2' => __( 'Value 2' ),
'value3' => __( 'Value 3' ),
));
// button
$wp_customize->add_control('add_button', array(
'section' => 'samplecustom_section',
'settings' => 'sample-list',
'type' => 'button',
'capability' => 'edit_theme_options',
'input_attrs' => array(
'value' => '+',
'class' => 'customizerbutton button-primary',
)
));
here is a sample image where when I click the plus button the select field will increment (or decrement by minus button) creating new ids for the add-control customizer.
I'm using a wordpress real estate plugin for my project which is wpcasa, I already do some modification, But this thing takes my time to figure out.
I think they use array to get set values/labels on search form.
Anyone can Help me to how to add default value into a search form?
Here's the code below
$defaults = array(
'keyword' => array(
'label' => __( 'Keyword or Listing ID', 'wpcasa' ) . '…',
'type' => 'text',
'class' => 'width-3-4',
'priority' => 10
),
'submit' => array(
'label' => __( 'Search', 'wpcasa' ),
'type' => 'submit',
'class' => 'width-1-4',
'priority' => 20
),
'offer' => array(
'label' => __( 'Offer', 'wpcasa' ),
'key' => '_price_offer',
'data' => wpsight_offers(),
'type' => 'select',
'data_compare' => '=',
'class' => 'width-1-5',
'priority' => 30
),
'location' => array(
'data' => array(
// wp_dropdown_categories() options
'taxonomy' => 'location',
'show_option_none' => __( 'Location', 'wpcasa' ),
'option_none_value' => '',
'hierarchical' => 1,
'orderby' => 'ID',
'order' => 'ASC'
),
'type' => 'taxonomy_select',
'class' => 'width-1-5',
'priority' => 40
),
'listing-type' => array(
'data' => array(
// wp_dropdown_categories() options
'taxonomy' => 'listing-type',
'show_option_none' => __( 'Type', 'wpcasa' ),
'option_none_value' => '',
'hierarchical' => 1,
'orderby' => 'ID',
'order' => 'ASC'
),
'type' => 'taxonomy_select',
'class' => 'width-1-5',
'priority' => 50
),
$details['details_1']['id'] => array(
'label' => $details['details_1']['label'],
'key' => '_details_1',
'data' => $details['details_1']['data'],
'type' => 'select',
'data_compare' => '>=',
'class' => 'width-1-5',
'priority' => 60
),
$details['details_2']['id'] => array(
'label' => $details['details_2']['label'],
'key' => '_details_2',
'data' => $details['details_2']['data'],
'type' => 'select',
'data_compare' => '>=',
'class' => 'width-1-5',
'priority' => 70
)
);
`
Example on keyword I will set a value HOME Instead showing its label.
Thank you!
I got it now I should add 'default' => 'Myvalue',
example
'keyword' => array(
'label' => __( 'Keyword or Listing ID', 'wpcasa' ) . '…',
'type' => 'text',
'class' => 'width-3-4',
'default' => 'HELLO',
'priority' => 10
),
Thanks for the help/advice!
I have the following form element configured and i don't know why the values are not preselected.
$this->add(array(
'name' => 'item_ids',
'type' => 'Select',
'attributes' => array(
'id' => 'item_ids',
'class' => 'form-control',
'multiple' => 'multiple',
'value' => array('1','2'),
),
'options' => array(
'label' => 'Items',
'label_attributes' => array(
'class' => 'col-sm-2 control-label',
),
'value_options' => array(
'1' =>'Item 1',
'2' =>'Item 2',
'3' =>'Item 3'
),
)
));
I want that the "Item 1" and "Item 2" are preselected.
I hope someone can help me with my problem.
#### Update ####
Found something like that in the documentation, i will give it a try :
'value_options' => array(
array(
'value' => '1',
'label' => 'Orange',
'selected' => true,
),
array(
'value' => '2',
'label' => 'Lemon',
),
),
you can set form values like :
$form->getElement('selector')->setValue('val');
or
$form->setDefaults(array(
'selector' => 'val'
));
As I mentioned in the Update of my first post, I found something that seemed to be the right way.
I tested it and this is the solution :
$this->add(array(
'name' => 'item_ids',
'type' => 'Select',
'attributes' => array(
'id' => 'item_ids',
'class' => 'form-control',
'multiple' => 'multiple',
),
'options' => array(
'label' => 'Items',
'label_attributes' => array(
'class' => 'col-sm-2 control-label',
),
'value_options' => array(
array(
'value' => '1',
'label' => 'Item 1',
'selected' => true,
),
array(
'value' => '2',
'label' => 'Item 2',
'selected' => true,
),
array(
'value' => '3',
'label' => 'Item 3',
),
),
)
));
I'm attempting to add data- values on radio buttons within ZF2. Is it possible to control each of the inputs specified with value_options?
A typical radio button added to a form:
$this->add(array(
'type' => 'radio',
'name' => 'duration',
'options' => array(
'value_options' => array(
'daily' => 'Daily',
'weekly' => 'Weekly',
'monthly' => 'Monthly',
),
),
));
Ultimately, I would like something like the following, so I can specify individual parameters/options for each radio item:
$this->add(array(
'type' => 'radio',
'name' => 'duration',
'options' => array(
'value_options' => array(
array(
'attributes' => array(
'value' => 'daily',
'data-item' => 'apple'
),
'options' => array(
'label' => 'Daily'
)
),
array(
'attributes' => array(
'value' => 'weekly',
'data-item' => 'orange'
),
'options' => array(
'label' => 'Weekly'
)
),
array(
'attributes' => array(
'value' => 'monthly',
'data-item' => 'pear'
),
'options' => array(
'label' => 'Monthly'
)
),
),
),
));
My reason for wanting the above, is that I want to use JavaScript to change something upon selecting a radio button, so it needs to hold data attributes.
Is anything like this possible yet?
It can be done by providing an array (or an object which implements ArrayAccess) instead of a single value (almost as you wrote in your example).
$this->add(array(
'type' => 'radio',
'name' => 'duration',
'options' => array(
'value_options' => array(
'daily' => array(
'label' => 'Daily',
'value' => 'daily',
'attributes' => array(
'data-item' => 'apple',
),
),
'weekly' => array(
'label' => 'Weekly',
'value' => 'weekly',
'attributes' => array(
'data-item' => 'orange',
),
),
'monthly' => array(
'label' => 'Monthly',
'value' => 'monthly',
'attributes' => array(
'data-item' => 'pear',
),
),
),
),
));
https://github.com/zendframework/zf2/blob/master/library/Zend/Form/View/Helper/FormMultiCheckbox.php#L177
This should work on radios, multi-checkboxes & selects too.