Multiple Relation Item in Netlify CMS - netlify-cms

I've two collections
Posts
Categories
In my case, each post can have multiple categories.
Hence the way I'm setting it is
Post has a field of type List which is further a Field of type Relation.
Is there a straightforward way to specify this relationship?
Thanks

The Relation widget has a multiple option that, when set to true, will do just that without having to rely on a list widget.
eg:
fields:
- label: 'Categories'
name: 'categories'
widget: 'relation'
collection: 'categories'
value_field: '{{slug}}'
display_fields: [title]
search_fields: [title]
multiple: true

Related

Wordpress multiple ajax filtering for custom post type with two taxonomies

I need help for a custom post type archive page.
I want to build three filters for a custom post type with two taxonomies registered. The first taxonomy is hierarchical like category, the second not hierarchical like tag.
The first filter is for hierarchical taxonomy parent elements. The second filter for non hierarchical taxonomy . The third is for hierarchical taxonomy child elements.
I want to make the first filter( hierarchical taxonomy parent elements) feed the second(non hierarchical taxonomy elements) and third(hierarchical taxonomy child elements), and then show results. Any ideas?
First, I have a ul list with all parent elements of the first taxonomy. By clicking on a specific li element, I am calling an ajax function that changes the second filter that contains all the child elements of the parent taxonomy.
I try to find a way to make get_terms() work in functions.php so as to use it in an ajax function. I get variable $product_type_id through ajax javascript. It is a variable to store the parent taxonomy term_id, and want to use it so as to get the children of the specific product type.
function getCurrentTerm($product_type_id){
global $product_type_id;
$my_products = get_terms([
'taxonomy' => ['awarded_product'],
'hide_empty' => false,
'parent' => $product_type_id ,
'order' => 'DESC'
]);
return $my_products;
}
function set_product_type_filter(){
$product_type_id = $_POST['product_type_id'];
if( $_POST['product_type_id']!=''){
$my_product = getCurrentTerm($product_type_id);
$response['product_type_id'] = $_POST['product_type_id'];
$response['product']=$my_product;
echo json_encode($response);
wp_reset_postdata();
wp_die();
}
}
add_action('wp_ajax_set_product_type_filter', 'set_product_type_filter');
add_action('wp_ajax_nopriv_set_product_type_filter', 'set_product_type_filter');

Disable sorting option in yii2

I'm new to Yii2 framework.
I have this Business view page like this..
Where for now a user can sort with all the four i.e business name, address, contact number and created date. I want to disable the sorting option for address and contact number. I found some options like 'sort' => false, but did not understand in which part of the code I should use it. Should I have to include the code in models? or controllers? or in the forms? Please help. Any guidance will be greatly appreciated.
Using enableSorting => false disable sorting for particular column of GridView .
E.g.
[
'label' => 'Address',
'attribute' => 'address',
'enableSorting' => false,
],

Symfony2, dynamically refresh form choices

I am creating a simple Blog system with symfony2. Each blog Post is bound to a certain amount of Tags.
Tags can be selected with checkboxes when creating a new blog post. Now I want to be able to dynamically add new tag-checkboxes to the form.
The AJAX part is done and working, I can add new tag names to the Tag entity and append the new checkboxes to the form.
The problem is when I submit the form, symfony2 doesn't recognize the new added tags because they don't belong to the Tag entity yet (at the time the form was generated).
For example: after submitting the form, I dump:
$tags = $form->get('tags')->getData();
The controller ignores the tags that were added through ajax.
I know it has to be solved with events somehow, I already read this documentation: http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html but can't figure out how to implement it for this specific case.
Here is my form builder for "PostType":
$builder
->add('title')
->add('content', 'textarea')
->add('tags', 'entity', array(
'class' => 'Bundle:Tag',
'property' => 'name',
'multiple' => true,
'expanded' => true,
))
->add('save', 'submit')
;
You can try to use this: Form Collection
Make sure you persist the newly added Tags before submit the form, and the checkboxes has the right names and values.
Names should be like "post[tags][]" and values should be the database ids of the Tag entities.

Magento: Add a multi-select attribute to categories with existing source?

I have an existing 'brand' select-attribute.
Is there a way to add a multiple-select field to categories with values from this attribute (Perhaps something similar to how I'd add a Yes/No attribute to categories)?
Here is an example of how you can create a product attribute with custom options. It works the same for categories.
Just change this:
$this->addAttribute('catalog_product', 'provider', array(
to this:
$this->addAttribute('catalog_category', 'provider', array(
The main idea is to give the attribute a custom source that is a model with a method that returns all the options.
TO get all the options of brand attribute, do this:
$options = Mage::getModel('eav/config')->getAttribute('catalog_product', 'brand')->getSource()->getAllOptions();

How to sort only top menu by category custom attribute in magento?

I have 15 categories created. and in left navigation i need categories in default order.
But in top menu I need to display categories in specific sort order. For that I have created attribute and followed this link.
So from above link, sorting is done by name, but i need to sort by int value stored in custom attribute
So please help anybody!!
You could use the function you mentioned with a small alteration: instead of getName() use getYourAttribute().
That is, however, not all. The nodes of the menu tree do not have your attribute in their internal data storage yet. To add it there, you'll have to create a class that overrides the catalog observer model, specifically the function Mage_Catalog_Model_Observer::_addCategoriesToMenu. this function is responsible for populating the top menu with category nodes.
Make sure that your overridden function adds your attribute in this procedure:
$categoryData = array(
'name' => $category->getName(),
'id' => $nodeId,
'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
'is_active' => $this->_isActiveMenuCategory($category),
'your_attribute' => $category->getYourAttribute()
);
I feel uneasy about modifying the lib files with custom code, as the tutorial suggests, but if this is your last resort...

Resources