Closed mittus closed 5 years ago
Hi mittus, I'm not sure I understand what you're up to.
if($dropdown_field) { $dropdown_field->set('position', 1); $dropdown_field->set('type', 'dropdown'); $dropdown_field->set('options', $options); $contest->save();
What does $contest->save()
actually do in your example?
If I have got it right, do you want to create some kind of 1:n relationship between the items? If yes, why does it have to be a dropdown field?
My customer need create items in category_1 and chose them for items in category_2
List items from category_1
List Dropdown box field options from item in category_2
$contest->save();
- it's my error. It is $dropdown_field->save();
Okay, I get it. I'm on my way, check it out later... ;-)
I'd take a different approach:
I would extend the functionality of ItemManager admin methods by adding your own logic. Here are the methods you should work with: Admin::buildItemEditor()
, Manager::deleteItem($id, $catid)
and Manager::saveItem(& $input)
.
Take a look at this article, there I described how you can extend ItemManager functionality without having to modify the core files. It's relatively easy because you only have to copy most of the native function code.
Note: you'll need to copy the plugins/imanager/lib/inc/config.php
file to data/imanager/settings/config.php
directory and set the $this->injectActions
variable to true
, so you are able to inject your logic into the ItemManager methods.
I had to do something similar once, at that time I worked with cities and countries. I'll give you an example so you can see how I solved that. Just a moment, please.
Here is a plugin that should demonstrate the functionality, you can play with it if you want: https://gist.github.com/bigin/7ace7c26314fc394b83a38498c3a0c09
To be able to test this example, you have to create 2 categories:
and ...
Now, you've to create a bunch of cities:
When you create the countries you will see the dropdown field:
Hope that helps you a little ;-)
I used similar method, variant with custom option and $selected[$city->id] = $city->name;
will solve my problem. Thank You!!
https://gist.github.com/mittus/dc0118a366b3b527588581bd3afc268c
Hello, friend!! I have a question about function with update Dropdown box field.
My structure:
Category_1
Category_2
Now I use script, that starting after saving Category_1 items:
And I did some fix in /lib/Field.php:
AND now it's work. But I whant use ID's from items instead names, Now I whant write some script with names map for ID's to Category_2 Chunk field. But I can't write "" in
$chunk_field->set('options', $script);
, becouse set function use sanitizer.What you think about that? It need some new method, or I can change set function with some crutch?
Thank You!! :))