Change tt_content's TCA for a subtype? - plugins

Is it possible, for a specific plugin (e.g. newspage_pi1), to configure its TCA, i.e. its back-end form display? Just for that specific plugin, because when changing tt_content's TCA for the list type (i.e. plugins) like this:
$GLOBALS['TCA']['tt_content']['types']["list"] = [
'showitem' => "
(tabs..palettes..columns..etc...)"];
It changes it for all plugins, and I only want to change it for the newspage_pi1 list_type.
Yes, I know that I can use 'subtype_value_field' => 'list_type' and then subtypes_excludelist and subtypes_addlist to add or remove fields for specific plugins. But this is not nearly as powerful as setting showitem directly, since it allows to define new tabs, palettes, position the fields how you want to, etc.
I also know about FlexForms, but these only control the Plugin Options field, not all the other ones.
Is there a way to change the showitem for a specific plugin?
Thanks a lot in advance!

Frankly said, what you actually want is not a subtype but another type, since it needs to change fields other than the usual plugin / pi_flexform configurations.
So instead of adding that subtype as a plugin you should add it as another CType to get the full power of showitem.
Basically, this is how we add any kind of plugin too, since it makes more sense to have real database fields at hand instead of faking them with XML data structures.
As mentioned in the description here https://api.typo3.org/master/class_t_y_p_o3_1_1_c_m_s_1_1_core_1_1_utility_1_1_extension_management_utility.html#ab4f6c66990aca246eac5390a76f0c83c
... - or more generally use this function to add an entry to any
selectorbox/radio-button set in the FormEngine

Related

Mask input for sap.m.Date(Time)Picker

With the sap.m.DateTimePicker, it's possible for a user to either select a value from the drop-down list or enter it manually. I'm wondering if there's a way to add a mask to the manual input box that matches the valueFormat of the DateTimePicker.
I know there's a sap.m.MaskInput as well, so maybe there's a way to combine the two elements.
There is a new private module named sap.m.MaskEnabler which the sap.m.InputBase (i.e. DateTimePicker) is supposed to make use of.
(MaskEnabler) should be applied to the prototype of a sap.m.InputBase.
The mask feature is currently enabled only in sap.m.TimePicker (v1.54). According to this commit message, however, the same feature will arrive to the Date(Time)Picker as well:
This change prepares for refactoring of DatePicker and TimePicker so the
common code of both pickers can be moved to a new common control that
they may extend.
Therefore, if it's not urgent, and depending on your project, I'd not create a new custom control and then throw it away once the mask feature has arrived.
I'll update my answer when it's available.
Until then (and even afterwards), you can still guide the user to enter the data in the correct format via OData binding type sap.ui.model.odata.type.DateTime:
<DateTimePicker
value="{
path: 'myODataModel>myDateTime',
type: 'sap.ui.model.odata.type.DateTime',
constraints: {
isDateOnly: true,
displayFormat: 'Date'
}
}"
minDate="{...}"
maxDate="{...}"
/>
In contrast to formatter, type allows us to keep two-way data binding.
The entered value is automatically intercepted from updating the model data when...
It could not be parsed due to an invalid format (fires parseError)
It could be parsed but the constraints were violated (fires validationError)
If you enable handling UI messages
additionally, the framework will then take care of creating the appropriate
message for the user:
Example: https://stackoverflow.com/a/48482544
I think the only way to combine the two sap.m.DateTimePicker and sap.m.MaskInput is to develop your own control . Documentation : https://sapui5.hana.ondemand.com/#/topic/91f1703b6f4d1014b6dd926db0e91070.
Another way is to just use the Placeholder of the DateTimePicker Input field. This does not provide the same functionality as a MaskInput, but helps the user which valueFormat is expected in the input when entering it manually.
If you have a binding in your input box, you could set the type in the binding to eg. sap.ui.model.type.Date. This way you get some automatic formatting when field validation is triggered. There are other types available and you could inherit from sap.ui.model.SimpleType to code your own.

Add default content to tinyMCE in Plone 5.0

I am working on a Plone 5.0 setup and I want to modify it in a way, so that users, who wants to create a new page, have a default text in their TinyMCE editor.
I am quite new to Plone and a bit overwhelmed by the amount of different languages and how they interconnect with each other. So instead of working on some files quick and dirty, I would like to have some suggestions how to start working on the problem properly and efficient.
Any suggestions, how to work on that are welcome.
The front-end (in this case TinyMCE) is not responsible for the default value, it's the form beneath.
Plone 5 uses Dexterity types with z3c forms.
EDIT: This is how your doing this the old school way - I mean the plone directives way -
Sry for misleading you. I still use plone.directives, which supports this kind of default value adapter.
The default content type Document of plone.app.contenttypes is using plone.supermodel. This has a different concept.
If you are still willing to create your own Richtext behavior you may follow those instructions: http://docs.plone.org/external/plone.app.dexterity/docs/advanced/defaults.html
In your case:
def richtext_default_value(**kwargs):
return RichTextValue('<p>Some text</p>')
#provider(IFormFieldProvider)
class IRichText(model.Schema):
text = RichTextField(
title=_(u'Text'),
description=u"",
required=False,
defaultFactory=richtext_default_value,
)
model.primary('text')
You can add a defaultFactory to the text field.
If you hack those lines on your egg, it will work.
Here's some information about setting a default value programmatically:
https://pypi.python.org/pypi/plone.directives.form#id8
How do you override the default value of a field in a dexterity behavior in Plone?
So in your case this may look something like this:
from plone.directives.form import default_value
from plone.app.contenttypes.behaviors.richtext import IRichText
from plone.app.textfield.value import RichTextValue
#default_value(field = IRichText['text'])
def richtext_default_value(data):
return RichTextValue('<p>Some text</p>')
You may extend the default_value decorator by context parameter to be more specific: #default_value(field = IRichText['text'], context=my.package.content.interfaces.IMyType)
BUT since we have the concept of behaviors it's may be better to implement your own Richtext behavior with a default value:
Creating a behavior --> http://docs.plone.org/external/plone.app.dexterity/docs/behaviors/creating-and-registering-behaviors.html AND the plone default richtext behavior as template for your own -> https://github.com/plone/plone.app.contenttypes/blob/1.2.16/plone/app/contenttypes/behaviors/richtext.py
Remove the ´plone.app.contenttypes.behaviors.richtext.IRichText` Behavior from your content type (Document) thru ZMI (portal_types -> Document)
Add your own Richtext behavior, this may be something like my.package.behaviors.richtext.IRichtextWithDefaultValue.

Custom content assist for default java editor in Eclipse

I'm currently trying to develop an Eclipse Plugin to support code replacement, like what the default content assist in Eclipse do. What I want to implement is something like "insert argument names automatically on method completion with visualized box around the argument" and I can "use the Tab key to navigate between the inserted names" and "while navigating, list of optional variables for current argument can be displayed and be chosen".
In short, it comes to two questions:
How to add the visualized box around the already existed variable or even Java keywords that need replacement? And at the meanwhile I can use Tab key to switch between these boxes.
How to display a list of candidates to select from when I trigger on the box?
By now I only figure out the extension point : org.eclipse.jdt.ui.javaCompletionProposalComputer may be useful, but I have no idea where to start at? Thanks in advance.
Oh, finally I've solved it myself...
For the 'box', it should be the LinkedModeModel, this class should work with LinkedPositionGroup and LinkedPosition to add mutiple boxes. And we should use LinkedModeUI to set it up.
For the content assistant, there's no need to use the extension point. There is a ProposalPosition class which extends LinkedPosition for you to add your proposals for the 'box' in its constructor. And we can simply use the CompletionProposal to construct a ICompletionProposal array as the argument of ProposalPosition's constructor.

Drupal 7 - Hide certain form fields of a content edit form depending on the content data

In Drupal 7, is there a way to change the standard edit form for a content type based on a certain content?
For example:
I have a content type with a checkbox...once it it checked and the form is saved, I do not want this checkbox to be visible anymore...therefore based on the checkboxes value in the Database I want to hide form fields when showing the form.
I am building a small specific project site, where a company wants to add projects, and their customers are supposed to follow certain steps (upload some content, provide information etc.), and also should be able to check off certain requirements, and once these are checked off, they should not be visible/editable to them.
Also the displayed form fields should depend on an user's role, and then FURTHER be limited depending on the content's database entries.
Is there a module, which could achieve this behaviour? "rules" and "field/permissions" come close to what I need, but are not sufficient. Or did I just miss the option to change a form field's accessibility based on conditions?
What I need is some place to define a logic like "IF (VALUEOF(CHECKBOX_1) == TRUE) THEN DO_NOT_SHOW(CHECKBOX_1)"
hook_form_alter is the way to do this, as explained by Mihaela, but what options do you have inside that function?
If you want just to disable field (it will be visible, but user can't change it) you can do it like this:
$form['field_myfield']['#disabled'] = TRUE;
And if you want it to be hidden, but to keep value it has before editing the way to do that is:
$form['field_myfield']['#access'] = FALSE;
I.e. hiding it (somewhere I saw someone suggesting that):
hide($form['field_myfield']);
really hides the field, but after that, when form is saved this field has empty value, validation fails, etc, so that's not a good way to do this. Hiding makes sense only if you want to print separately that field later, at some other place.
function your_module_form_alter(&$form, &$form_state, $form_id){
switch($form_id) {
case 'nameOfTheNode_node_form':
//your code here. check the value from from_state.
break;
}
}
In this case, I use module Conditional Fields https://www.drupal.org/project/conditional_fields
For example: If my Dependees field has a value, Dependent field can be visible/invisible, enabled/disabled, required/optional, checked/unchecked

Symfony2: Entity instantiation upon Form-Submit depending on user selection

I'm working with Symfony2 to set up a form, where a Shelf-Entity can be edited.
A shelf contains a collection of Readable-Entities (e.g. Book, Magazine, etc. - all inherit from Readable).
The user has the possibility to add more Readable-Entities (the form is extended via JavaScript) and from a dropdown he can select the type of Readable he wants to add. Depending on the selected dropdown-value, different form fields are rendered. So far so good.
Now, when the form is submitted to the server, depending on the Readable-Type the user selected in the form, a different entity-type should be instantiated.
If I don't do anything, Symfony just instantiates the base class Readable (and not Book, Magazine, etc.).
How can I tell Symfony to instantiate the correct type of Readable depending on the selected value from the dropdown?
I tried with FormEvent-Listeners, but:
in PRE_SUBMIT I only get an array containing the "raw" form data with $event->getData(), i.e. no entities have been instatiated so far. However, at this stage, I still have access to value of the dropdown.
in SUBMIT the form data was already assigned to the appropriate entities. Also the new Readable was already instatiated with the base Readable-Class. But now, I cannot access anymore the value from the dropdown.
What is the correct way to do this?
EDIT
Added a minimal Code-Example for the Shelf FormType:
https://gist.github.com/anonymous/401495b701982adafb96
Code for infinite_form_polycollection:
https://gist.github.com/anonymous/b5f0ed10ca9c52177f01
Have you tried looking at this part of the doc? As "embedding a form" seems to fit your needs.
It seems that there was something wrong with the PHP-Files of the PolyCollection in the vendor-directory, because after removing everything related to the Infinite Form Bundle from the vendor-dir and reinstalling it with composer, everything is working now. But thanks for your efforts YoannCh