Standard form type for editing mutlivalue? (Symfony CMF PHPCR) - sonata-admin

I'm using Sonata Admin as a backend. I have within PHPCR Document field that is multivalued (i.e. in PHP an array of strings). Now I'd like to add/remove elements from it within Sonata admin. Which type should I use? Tried collection, but I get nothing in admin; when I try sonata_type_collection admin expects from me admin code (I guess another admin), which is not the case.
Which form type should I use for a Document's field like the one below?
/**
* #PHPCR\String(nullable=true, multivalue=true)
*/
protected $tags;

There is a chapter on form types for PHPCR-ODM in the cmf documentation. There is BurgovKeyValueBundle that allows you to edit associative arrays. For non-associative multivalue fields, i think you just need to use the array type of sonata admin.

Related

How can the category and product fields in Shopizer be customized, if possible at all?

I am currently using Shopizer as a sort of headless CMS, leveraging its out of the box admin pages and REST API for the content. There is a page for editing products in the admin system but I would like to add and/or remove specific fields. Making changes to the base code seems to be the most obvious solution but it is taking me a significant amount of time to implement it successfully.
Is there some sort of a config file or an initialization process to customize the fields for creating categories and products using Shopizer's admin page? What is the best practice for this scenario if the former approach is not possible?
If you need to add fields the easiest way is to add them in model objects
com.salesmanager.core.model.*
Example of an annotated field
#Column (name ="IP_ADDRESS")
private String ipAddress;
Once you restart your instance the new field will be available.

ManyToManyField is not getting saved in Wagtail Page

I have a subclass of Wagtail Page class that has field of django ManyToManyField type. When I try to create a new instance of my page object, I get a list of objects that the the ManyToManyField points to and I am able select multiple items. However, after creating that page when I try to edit the same page, it seems no data got saved for the ManyToMany field. I know in Django ModelAdmin one have to override the save_related() to save ManyToMany field data. Is there a similar method for the Wagtail Page model?
You should define the field as a ParentalManyToManyField relation, as per the example here: http://docs.wagtail.io/en/v1.13.1/getting_started/tutorial.html#categories
This is a variant of ManyToManyField which is able to keep track of the relation in memory, allowing it to work in situations such as previewing and saving as draft (where it doesn't get saved to the normal database records).
I was able to use the 'after_edit_page' and 'after_create_page' hooks to save the data for the page's ManyToMany fields.

CakePHP 3 How to detect if an entity field is changed

I'm developing a CakePHP 3 application.
Now, i need to encrypt some data with SHA1 before the save of the entity.
I tried the beforeSave() callback in Table Object, like in CakePHP 2.x, but it doesn't work.
So, i discovered that type of change (update data on beforeSave/beforeUpdate) in current version, needs to be adapted to accessors & mutators, like the docs says (http://book.cakephp.org/3.0/en/orm/entities.html#accessors-mutators).
Documentation even has a note about check if an entity field was modified (http://book.cakephp.org/3.0/en/orm/entities.html#checking-if-an-entity-has-been-modified) but i dont understand how to use this.
I need some simple logic, just like an authentication system.
Before Save, in User Model, the field responsible_card_password must be hashed with SHA1 if this is filled. If isnt filled, the field stays the same.
Currently, with the acessors and mutators method, if i put the field on form blank, the entity save this field blank.
How i can solve this? Very thanks CakePHP developers on the world! :-D
you can add code in your entity table to auto hashing password
protected function _setPassword($password)
{
return (new DefaultPasswordHasher)->hash($password);
}

Create new field type for custom content

I want to create a new content type called "Message". It will have a couple of fields, "message-body" which will be plain text and "addressees". The addressees field should reflect a list of the registered users of the site.
The idea is to create a field type that will be a checklist where all users of the site can be selected, and those that are will receive the message in "message-body" via drupal_set_message($msg).
I am not suceeding so far in creating a custom field type. The Field API documentation is not very clear.
Thanks.
You maybe already found the solutions for you problem.
I think in your case you can use Entity Reference. In your custom content type you can create a new field with the Entity Reference type. Then on the configuration page you can choose which entity to reference, like node, taxonomy or users, with different types of widget.
Here's a link of the Entity Reference module.
Why not make a content type via the menu interface www.yoursite.com/admin/structure/types/add.
Or you need it as a module that you can re-distribute?
An easier way then is to make use of features. It allows you to 'export' a built content type into a module. Enabling the module (on another site), then creates all the fields that where in the export.

CakePHP set input type in view from custom array

I would like to assign input fields in a view types from a custom array, not from a model, as Cake usually does.
So, I have in my array (passed to the view) a key which tells the field type the field in the database must have:
[type] => 'varchar(32)'
I would like Cake to know this field type and automagically assign it to the corresponding input field (so that, for the example above, the input will be a text). How can I achieve this?
Thank you.
P.S.: These are the 'transformations' I would like to achieve (from the table): Data types correspondings in Cake
linkyndy,
The mapping from model schema types to html form elements is done here - http://api.cakephp.org/view_source/form-helper/#l-738. Furthermore, varchar(32) (string) will create an html input element when using the FormHelper. Is it you want a textarea instead?
If you do not want to use the automatic field detection you can specify the element type in your call to input. If that's not acceptable, you can change your db field types to meet what CakePHP expects... or manipulate your model's schema() results... or provide your own helper with an overridden input() method.
Specifying the type in calls to $this->Form->input() seems easy enough.

Resources