Disable sorting option in yii2 - sorting

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,
],

Related

Magento admin is only showing 2 custom attributes on product admin page, new attributes I've created don't display

A few months ago when I first started setting up this Magento 2 site I created the custom product attributes "size" and "style" in Magento Admin-- everything worked fine and whenever I am setting up any product, dropdowns for Size and Style show up in the Attributes section of Catalog/Products.
Now I have created three more custom attributes in Magento Admin that I want to use, and I have configured them the exact same way as my original two. However, dropdowns for these new attributes are not showing up in the Attributes section of Catalog/Products.
I have flushed the Magento cache and reindexed with no success. Does Magento only allow 2 custom attributes for products, or am I just missing something?
Did you create the custom attribute by code with your module or create it with Magento Admin?
For Magento Admin, please share the steps.
Please share the whole code which you write to create the attribute. Please confirm that follow the right steps:
Below code that you use to create a custom drop-down attribute.
/* Product Custom Multi Select Option */
$eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'custom_cms_pages');
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'custom_cms_pages',
[
'type' => 'varchar',
'label' => 'Custom CMS Pages',
'input' => 'multiselect',
'required' => false,
'sort_order' => 30,
'source' => \VendoreName\ModuleName\Model\Config\Source\CMSPageList::class,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'group' => 'custom_content_hide',
]
);

Laravel Backpack's CRUD data is not showing on custom operation form

I've been tinkering with Backpack for some moment and tried to create a custom operation called "Next Process". Basically, this operation is just an "edit" function with different fields to fill in (because we want the fields on the "create" function to be edited as well, and the filling of the "Next Process" will be done later after creating the data. So we don't want to just utilize the provided CRUD Edit trait).
The problem is, I am unable to show the value of the fields on this custom function's form. If we try to fill the form from scratch (with no existing data), The page works just fine. The value was stored and can be viewed on the "show" page. However, when we tried to go to the "Next Process" page again (now the field has been populated with some data), the existing data is not shown. Updating the form now resets all the existing data to empty, except for the field that we fill just now.
I have included the $this->data['crud'] = $his->crud and $this->data['entry'] = $this->crud->getEntry($id) at the beginning of the function, and passed the $data to the view. The view itself is just a published version of "edit" blade from Backpack's own template.
I have also tried to use the $this->view->getEditCrud() (just in case if the published template is the culprit), but the result is still the same.
What is wrong with this? I attach my code for reference.
public function getProcess($id)
{
$this->crud->hasAccessOrFail('update');
$this->crud->setOperation('process');
$this->crud->setHeading('Process '.$this->crud->entity_name, 'getProcess'); // set the Heading for the create action
$this->crud->setSubheading('Process '.$this->crud->entity_name, 'getProcess'); // set the Subheading for the create action
$this->data['breadcrumbs'] = [
trans('backpack::crud.admin') => backpack_url('dashboard'),
$this->crud->entity_name_plural => url($this->crud->route),
'Process '.$this->crud->entity_name => false
];
// get the info for that entry
$this->data['entry'] = $this->crud->getEntry($id);
$this->data['crud'] = $this->crud;
$this->data['title'] = 'Process '.$this->crud->entity_name;
$this->data['id'] = $id;
$this->crud->getEntry($id);
$this->crud->addField([
'name' => 'support_type',
'label' => 'Support type',
]);
// Redacted: Whole bunch of addField with the 'name' matching the database column's name
// (pretty sure it's not the problem since saving the form updates the specific field
// in the database).
$this->crud->addField([
'name' => 'third_pty_partnership',
'label' => 'Third Party Partnerships',
]);
$this->data['saveAction'] = [
"active" => [
"value" => "save_and_back",
"label" => "Save and go back"
],
"options" => [
]
];
return view('vendor.backpack.crud.processForm', $this->data);
}
Thanks in advance for your help!
Put the addFields before the calls to the info for the entry.

is there a way to show data in repeater field form after repeater is extended?

i did this in plugin.php boot function to addfield in repeater field
WartaRutin::extendFormFields(function($form){
if(!$model instanceof Kebaktian) return;
if(!$form->model->kebum) return;
if(!$form->isNested) return;
$form->addFields([
'addition' => [
'label' => 'addition label',
'span' => 'storm',
'cssClass' => 'col-sm-4',
'type' => 'text']
]);
});
the result produce additional field perfectly.. the problem is after data is saved, it doesn`t show in the form but data exist in database,,
how should i solve this..
yes, you are correct we dont need to worry about database fields.
as repeater field is build of json so in database its json and when you fetch from database its array
just take structured input from user then use : extend-form-fields octobercms.com/docs/backend/forms#extend-form-fields
now you can add and remove fields from the repeater as user needed.
if any doubts please comment

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.

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