Multiselect rendered as tags in documents - pimcore

In Data Objects we have the possibility to render multiselects as tags. Is it possible to achieve the same functionality in documents?
We have tried the following but nothing seems to change:
<?= $this->multiselect($filter, [
"width" => 200,
"height" => 150,
'renderType' => 'tags',
"store" => \InteliveBundle\Model\Utils::getSelectOptions($filter),
"reload" => false,
'class' => "editmode-cssid",
'htmlspecialchars' => false,
]); ?>

According to the documentation you have the following configuration options:
store array Key/Value pairs for the available options.
width integer Width of a generated block in editmode
height integer Height of a generated block in editmode
class string A CSS class that is added to the surrounding container
of this element in editmode
https://pimcore.com/docs/6.x/Development_Documentation/Documents/Editables/Multiselect.html
Therefore this feature seems not to be implemented. You can make a feature request in https://github.com/pimcore/pimcore or even better you fork the project, implement this feature and make a merge request.

Related

How do I prevent a re-render of a large list?

I have a 60x30 grid for a game editor and as cells are updated, a new array is created to hold the state.
The problem is that when I update that grid array, this changes the property and it causes render() to recreate the grid. This seems almost obvious but then what do my options become?
If this is overly specific, imagine just a huge list of items and you have an immutable array in which one of the items properties must change.
render() {
return html`
${this.data?.cells.map((row) => {
return row.map((cell) => {
return html`<editor-cell .data="${cell}"></editor-cell>`;
});
})}
`;
}
Coincidentally, I had the same problem on Angular with a for loop only it had trackBy which used the index or item.id to prevent the recreation of a list of items. I just accepted the unicorns for that but here it is the same issue.
Question:
What am I missing about immutable states here? I totally understand why this is happening in that, its a new array and so lit element just renders what it deems a new array. I want that, but once the grid has been rendered, I don't understand the separation between rendering and data updates. I'm either missing a key lifecycle understanding, or my approach to state is just totally whack.
If you update the complete array this change the memory reference and then lit-html has to re-render the whole array because it doesn't know what item changes.
In the lit-html documentation you have a section about Repeating templates that explain that very well.
In your case you should use repeat directive, that performs efficient updates of lists based on user-supplied keys:
render() {
return html`
${repeat(this.data?.cells, row => row.id,
row => html`${repeat(row, cell => cell.id,
cell => html`<editor-cell .data="${cell}"></editor-cell>`
)}`
)}
`;
}
Notice the importance of the second argument, that it's the guaranteed unique key for each item.

Yii2 CRUD and Pagination

I am using Yii2 with Pjax for index/gridview listing. using pjax pagination , search all working fine without postback to server.
My problem starts now,
suppose i am on page number 2, i have clicked on edit record of that 2nd page list, i reach to update view, i have done changes and saved, now i am redirected to view , now i clicked on index link from breadcrumbs.
i want to reach to page number 2 of index rather then 1st page.
Traditional process for this is get refereeing page params an append that in breadcrumbs.
But is there any simple approach to this problem where i can write few lines of code and its applied to every where in backend?
Thanks for reading.
For remembering grid filter, pages i use yii2-grid-view-state
If you need to store page only, isn't it quite easy to pass page param into your view url (<model/view>) like <model>/view?id=<id>&page=<page>?
in your index.php view, edit your ActionColumn as follow:
[
'class' => 'yii\grid\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) {
return \yii\helpers\Url::to([$action, 'id' => $model->id, 'page' => Yii::$app->request->getQueryParam('page', null)]);
},
],
As you can see, I'm getting page param from request url and pass it to models' action buttons (to all buttons, but in your question it would be enough for view button of course)
And when you click to view model, in our Controller we need to get that page value and pass it to our view.php view (in order to place it in breadcrumbs).
Our ModelController:
public function actionView($id, $page = null)
{
return $this->render('view', [
'model' => $this->findModel($id),
'page' => $page,
]);
}
And finally view.php view will get the page value, and populate the index url (if not null):
/* #var $page int */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Index', 'url' => ['index', 'page' => $page]];
So when you press the Index breadcrumb, it will open the page, where you entered from.
Some advantages againts session implementation (#user1764431 solution):
Each of your tab can return to it's own last page
Simple and stupid solution
Some disadvantages:
If you need to store some filter params, url could stretch very long
Just add following Code in every controller of actionIndex() rest all things will take care
$searchModel = new CentervideosSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
/*Code insertion block begin*/
$params = Yii::$app->request->queryParams;
if (count($params) <= 1)
{
$params = Yii::$app->session['customerparams'];
if(isset(Yii::$app->session['customerparams']['page']))
$_GET['page'] = Yii::$app->session['customerparams']['page'];
if(isset(Yii::$app->session['customerparams']['per-page']))
$_GET['per-page'] = Yii::$app->session['customerparams']['per-page'];
}
else
{
Yii::$app->session['customerparams'] = $params;
}
$dataProvider = $searchModel->search($params);
/*Code insertion block Ends*/

OctoberCMS change backend menu organization

I want to change OctoberCMS backend menu organization.
Example:
I want to move from sidebar of Rainlab Plugin Static Pages - Menus to OctoberCMS CMS SideBar or it can be possible to add Rainlab Plugin Static Pages - Menus to main menu.
You can do this in your plugin.php file with registerNavigation function. For example this code define top menu and sidebar menu:
return [
'title' => [
'label' => 'title',
'url' => Backend::url('...'),
'icon' => 'icon-cube',
'permissions' => ['access.*'],
'order' => 501,
'sideMenu' => [
'title' => [
'label' => '....',
'url' => Backend::url('....'),
'icon' => 'icon-slack',
'permissions' => ['access'],
'order' => 500,
],
Also in your controller you must define this:
BackendMenu::setContext('Author.Plugin Name', 'plugin', 'model');
I know this might be really obvious but I'll still say it just to be sure. If you are looking at changing the appearance or location of Backend Menu Items provided by plugins you did not author, don't make any changes to those files yourself. You would just loose all such custom changes everytime you update that plugin.
A better idea would be to create your own plugin that uses the 3rd-party plugin as a dependency and then make required changes to this new plugin.
Example Case: You wish to alter the display of the RainLab.User plugin backend menu item.
Create a new plugin and name it as needed. For ex: Acme.UserExtension.
Now in the plugin.php file of this new plugin you can add a dependency on the RainLab.User plugin and then hide it's menu item like so:
public $require = ['RainLab.User'];
public function boot()
{
/** Add a side-menu item */
Event::listen('backend.menu.extendItems', function($manager) {
$manager->addSideMenuItem('RainLab.User', 'user', [
'payments' => [
'label' => '...'
]
]);
});
/** Add a custom main-menu item */
Event::listen('backend.menu.extendItems', function($manager) {
$manager->addMainMenuItem('Acme.UserExtension', 'user');
});
/** Remove the original main-menu item */
Event::listen('backend.menu.extendItems', function($manager) {
$manager->removeMainMenuItem('RainLab.User', 'user');
});
}
As you can see you can completely remove a menu item for a plugin you dont own if you want. You could just extend it like shown above and just use the registerNavigation() method to do what you need for this extension plugin. You might have to replicate some of the menu items you do want to retain from the original parent plugin but now you have the ability to add some of your own or remove the items you don't need.
More details on how you can do this are here -> http://octobercms.com/docs/plugin/extending#extending-backend-menu
Hopefully this isn't too convoluted and helps you out.
While extending standard October backend controllers is very easy and described in documentation (mentioned in answers above), manipulations with Static Pages by RainLab are more complicated as "side navigation" (tabs) is handled with JavaScript. It's not possible to add a new item to this plugin navigation through the methods from the October CMS docs or to add "menu" sidemenu item to another plugin. With standard extend it's possible to show only one tab (you were asking about menu) but this won't set it as default and "pages" will still be shown as default.
If you are using only Static Menu my solution is to rename top menu Pages -> Menus and hide all tabs except "menu" with permissions (they will still be visible for admin but at least won't confuse backend editor). Will be happy if someone will share a better solution.
The code to place in your custom plugin, in boot() + don't forget to set permissions while creating a backend user for the client.
// Rename rainlab.menu pages to menu
Event::listen('backend.menu.extendItems', function($manager)
{
$manager->addMainMenuItems('RainLab.Pages', [
'pages' => [
'label' => 'Menu',
'url' => Backend::url('rainlab/pages'),
'icon' => 'icon-align-justify',
'sideMenu' => [
'menus' => [
'label' => 'rainlab.pages::lang.menu.menu_label',
'icon' => 'icon-sitemap',
'url' => 'javascript:;',
'attributes' => ['data-menu-item'=>'menus'],
'permissions' => ['rainlab.pages.manage_menus']
],
]
],
]);
});

Removing the number of first page in Yii2 Pagination from the URL

For SEO purposes I need to remove the first page number from the URL. i.e I have the following:
example.com/pages/view/1 and example.com/pages/view the two URLs points to the same contents of the view action. I want to make the pagination free from 1 in the URL. i.e first Page link and Page Number 1 should be linked to pages/view.
I tried to deal with the $pagination object like the following:
$pages = new Pagination(['totalCount' => $books['booksCount'], 'pageParam' => 'start', 'defaultPageSize' => 10,]);
$pagingLinks = $pages->getLinks();
$pagingLinks['first'] = '/';
$pages->links = $pagingLinks;
However, the last line causing error:
Setting read-only property: yii\data\Pagination::links
So I have a problem to modify the links property. Is there any other solution to get this task done?!
According to docs you should set yii\data\Pagination::forcePageParam to false by passing it in Pagination constructor
$pages = new Pagination([
'totalCount' => $books['booksCount'],
'pageParam' => 'start',
'defaultPageSize' => 10,
'forcePageParam' => false,
]);
The above answer may works for direct use of Pagination but remain an issue if it was used from another widget such as ListView.
I found the solution from a comment on an issue report on Yii2 repository on github
The solution is just define proper route in config/web.php. Suppose here we have a controller called Suras and we use the ListView widget on its action's view called view. So placing rule array with defaults has value 'page' => 1 will prevent adding the page parameter to the link's URL of the first page. Also notice the first rule 'view/<id:\d+>/1' => 'Error404', is placed in-order to prevent any access to the first page using page=1 parameter, for example, trying to access mysite.com/view/20/1 will invoke 404 error, because there is no controller called Error404.
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'view/<id:\d+>/1' => 'Error404',
['pattern' => 'view/<id:\d+>/<page:\d+>', 'route' => 'suras/view', 'defaults' => ['page' => 1]],
'view/<id:\d+>/<page:\d+>' => 'suras/view',
'view/<id:\d+>' => 'suras/view',
],
],
],

validation on unbound form field

I have a form with an extra unbound field added using 'property_path' => false.
I would like to have a simple validation on this field and I've found many answers that suggest to use something like
$builder->addValidator(...);
but I've seen that in symfony 2.1 $builder->addValidator is deprecated. Does anyone know what is the correct way to put a validation on an unbound field in Symfony 2.1?
Edit :
I've just made a more complete answer on topic Symfony validate form with mapped false form fields
Original answer
Validating unbound (non mapped) field in a form is not well documented and the fast evolving form and validator components make the few examples obsoletes (for Symfony 2.1.2).
For now I succeed in validated non mapped fields with event listener.
Here is my simplified code :
namespace Dj\TestBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Form\FormEvents;
use Dj\TestBundle\Form\EventListener\NewPostListener;
class PostType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('lineNumber', 'choice', array(
'label' => 'How many lines :',
'choices' => array(
3 => '3 lines',
6 => '6 lines'
),
// 'data' => 3, // default value
'expanded' => true,
'mapped' => false
))
->add('body', 'textarea', array(
'label' => 'Your text',
'max_length' => 120));
// this listener will validate form datas
$listener = new NewPostListener;
$builder->addEventListener(FormEvents::POST_BIND, array($listener, 'postBind'));
}
// ... other methods
}
And the event listener :
namespace Dj\TestBundle\Form\EventListener;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormError;
/**
* listener used at Post creation time to validate non mapped fields
*/
class NewPostListener
{
/**
* Validates lineNumber and body length
* #param \Symfony\Component\Form\FormEvent $event
*/
public function postBind(FormEvent $event)
{
$form = $event->getForm();
$data = $event->getData();
if (!isset($data->lineNumber)) {
$msg = 'Please give a correct line number';
$form->get('lineNumber')->addError(new FormError($msg));
}
// ... other validations
}
}
This is how I validate my non mapped fields until I find out how to do this with validators.
I have the same problem from the docs we get this:
The interface FormValidatorInterface was deprecated and will be
removed in Symfony 2.3. If you implemented custom validators using
this interface, you can substitute them by event listeners listening
to the FormEvents::POST_BIND (or any other of the *BIND events). In
case you used the CallbackValidator class, you should now pass the
callback directly to addEventListener.
This suggest to use event listeners but I have not found and example.
https://github.com/symfony/symfony/blob/master/UPGRADE-2.1.md

Resources