TYPO3 FAL : add and read a custom field in a fluid template - typo3

In my custom extension I introduced a binary variable to the image metadata that needs to be read, similar to the "Show in list view" of tx_news.
With tx_news as example I was able to add the variable, the new palette shows the checkbox in the backend and the selection is registered in a new database field in the sys_file_reference table ...
I first tried to declare it in the domain which did work but I could not use the variable since it was an array of the same files in which I tried to use it, calling it within a loop broke the loop ... (this was my question)
now I need to use this new variable in my fluid template, if I loop trough the items the new variable named opentab is visible if I debug like this:
<f:for each="{object.items}" as="item" iteration="iteration">
<f:debug>{item.originalResource}</f:debug>
# debug result
TYPO3\CMS\Core\Resource\FileReferenceprototypeobject
propertiesOfFileReference => array(36 items)
uidOfFileReference => NULL
name => NULL
originalFile => TYPO3\CMS\Core\Resource\Fileprototypeobject
mergedProperties => array(empty)
propertiesOfFileReference has "title" which I can use like this {item.originalResource.title}
in propertiesOfFileReference I see "opentab" with its correct value but I found no way to use it !!!

Use {item.originalResource.properties.opentab}

Related

TYPO3 selectMultipleSideBySide translate "Available Items" per record type

I want to override the label strings "Available Items" and "Selected Items" in a selectMultipleSideBySide form because it is too generic. I have multiple record types using this form template so I cannot change the strings globally.
I tried to change it in the TCA of my custom record type without success. I only see the label for the entire relation.
I am using TYPO3 8.7
Does anyone know an extension which accomplished this or does anyone know the config path to there?
Thanks!
Edit:
In the class typo3/sysext/backend/Classes/Form/Element/SelectMultipleSideBySideElement.php at line 393 I found the translation path hard-coded. So I need to inherit from this class and register it as my new selectMultipleSideBySide in the TCA.
I copied the class TYPO3.CMS/typo3/sysext/backend/Classes/Form/Element/SelectMultipleSideBySideElement.php to my extension in Classes/From/Element/SelectTagCloudElement.php
I adapted namespace to my extensions.
I add a use-directive of use TYPO3\CMS\Backend\Form\Element\SelectMultipleSideBySideElement;.
I adapt the translation string like in line 221 to my custom records translation xml file.
I found on https://docs.typo3.org/m/typo3/reference-coreapi/8.7/en-us/ApiOverview/FormEngine/Rendering/Index.html a snippet to register an new NodeType (the class I extended previously) using:
// Add new field type to NodeFactory
$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1487112284] = [
'nodeName' => 'selectTagCloud',
'priority' => '70',
'class' => \MyVendor\CoolTagCloud\Form\Element\SelectTagCloudElement::class,
];
in ext_localconf.php
Now I can use selectTagCloud instead of selectMultipleSideBySide in the TCA.
"Dump Autoload Information" in the Install Tool
Done

TCA configuration: Value of field should be copied to translated record

I am adding a field to the pages table (is a relation to a file) and would like the value of the field in the pages record to be copied to the translated record by default.
Currently, the copied field is empty (default value), which is probably a good idea in most cases.
I am thinking of something that behaves like l10n_mode = prefixLangTitle without the prefix.
Depending on the TYPO3 version this should be possible with one of the following behaviours for the inline field:
https://docs.typo3.org/typo3cms/TCAReference/7.6/Reference/Columns/Inline/Index.html#behaviour
https://docs.typo3.org/typo3cms/TCAReference/8.7/ColumnsConfig/Type/Inline.html#localizechildrenatparentlocalization
https://docs.typo3.org/typo3cms/TCAReference/latest/ColumnsConfig/Type/Inline.html#allowlanguagesynchronization
Sine the localizeChildrenWithParentLocalization feature is broken with pages and pages_language_overlay though, I guess the only working versions would be CMS 8 or 9 with properly configured language synchronization.
https://forge.typo3.org/issues/78743
Use
['behaviour']['allowLanguageSynchronization'] => true
if the translated record will use the value from the default field by
default (will effectively be copied), but it should be possible to change
this later.
See pages.author as example.
When "Custom value" is selected, the value can be overridden.
Alternativively, use
l10n_mode = exclude
if the field should always have the value of the default language and you
should not be able to change it in the translated record.

How can I pull data in a controller and form for one model that is in a different model with out a foreign key relationship?

I am new to rails and haven't really done to much with data outside of the model.
I have a form that references a table controller for files. I want to add an dropdown that will display a list of projects from a project table for the user to assign a the file to a project if they want too. Assigning a project is not a requirement. The file can be unassigned to a project. I do have a project_id column in the file table for those projects assigned but it is allowed to be null and I did not build a relationship because I need to have cases where there are none.
Can someone please tell me how to do this?
When they evaluate the file, the screen posts back with a save or update button depending if it has already been saved in the database.
At the same time as the save and update pop up on the right I want to display a list box of the projects with an assign project button. If new just a list, if update either just a list because not assigned or display the selected value in the list if already assigned, while allowing them to change it from the list if desired.
In the file controller method that posts back to the UI I have this code:
#file_alias_filedata = FileAliasFiledata.all
#projects = Project.all
for update
#projects = Project.find(params[:id])
In the form I have this code:
<p> <label> Select Project to Assign:</label> <br />
<%= select_tag 'projects', (#projects.present? ? options_for_select(#projects, #selected_project) : []) %> </p>
The form runs but I get this in the dropdown box:
#<Project:0x))7ff531ab4518>
Can someone please help me figure out how to accomplish my task and why I see the strange box value?
What am I doing wrong?
Thank you for your help!
Assigning a project is not a requirement. The file can be unassigned
to a project. I do have a project_id column in the file table for
those projects assigned but it is allowed to be null
From the docs:
belongs_to(name, scope = nil, options = {}) public
Specifies a
one-to-one association with another class. This method should only be
used if this class contains the foreign key. If the other class
contains the foreign key, then you should use has_one instead. See
also ActiveRecord::Associations::ClassMethods’s overview on when to
use has_one and when to use belongs_to.
Methods will be added for retrieval and query for a single associated
object, for which this object holds an id:
association(force_reload = false)
Returns the associated object. nil is returned if none is found.
Likewise,
has_many(name, scope = nil, options = {}, &extension) public
Specifies
a one-to-many association. The following methods for retrieval and
query of collections of associated objects will be added:
collection(force_reload = false) Returns an array of all the
associated objects. An empty array is returned if none are found.
But belongs_to() and has_many() are supposed to make things more convenient for you. You certainly do not have to use them.
Next,
and why I see the strange box value? What am I doing wrong?
You see the strange value for the same reason the following two loops display different things:
class Dog
attr_reader :name
def initialize(name)
#name = name
end
end
#dogs = [
Dog.new("Sam"),
Dog.new("Betty"),
Dog.new("Pete"),
]
#dogs.each {|dog| puts dog}
#dog_names = #dogs.map {|dog| dog.name }
#dog_names.each {|dog_name| puts dog_name}
--output:--
#<Dog:0x0000010099a308>
#<Dog:0x0000010099a2b8>
#<Dog:0x0000010099a268>
Sam
Betty
Pete
You will see the same result if you do something like the following in a view:
<div>
<%= select_tag "dog", options_for_select(#dogs) %>
</div>
<div>
<%= select_tag "dog_name", options_for_select(#dog_names) %>
</div>
If you read the docs here:
http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select
...you will see several examples, which should make it clear that options_for_select() takes an argument that is:
An array of Strings.
A Hash where both the keys and values are Strings.
An enumerable that iterates over some Strings.
etc.
Do you see a pattern? It's Strings! options_for_select() needs an argument that consists of Strings. If the argument is not a collection of Strings, e.g. an array of project objects, then options_for_select() tries to convert the objects to strings by calling to_s() on the objects. And the default to_s() method is Object#to_s() which is inherited by all objects and produces a string containing the class name and the object_id.
I am also new to rails, but I think you can try using the options_from_collection_for_select method.
<%= select_tag :search_state, options_from_collection_for_select(State.find(:all, :select => :name), :name, :name) %>
Hope this help. Cause it certainly helped me.

Silverstripe FulltextSearchable add custom fields

I need a custom field to be FulltextSearchable. Therefore I tried this code as described in the FulltextSearchable class:
Object::add_extension('Page', "FulltextSearchable('SearchableContent')");
then run dev/build.
Basically Fulltext Search seems to work. But the content of the custom Field 'SearchableContent' seems never to be checked.
Of course I enabled FulltextSearch first by:
FulltextSearchable::enable();
Thx,
Florian
All SiteTree classes have their search columns define in FulltextSearchable like:
$defaultColumns = array(
'SiteTree' => '"Title","MenuTitle","Content","MetaTitle","MetaDescription","MetaKeywords"',
'File' => '"Title","Filename","Content"'
);
so I don't think SilverStripe will pick up on your extra column. Unless you edit the FulltextSearchable but that's probably a bad idea... or just create a custom search function like for plain DataObject so you can specify exactly which columns to search on:
silverstripe dataobject searchable

How to add a custom field button to a field in SugarCRM

I looked through the developer blogs and I can only find ways to create a custom global form button or to replace a field with custom code. I don't want to replace the field, I want to add a button beside a field.
Here's what I have in mind:
[Date Field][date_picker_button] [time field][time_is_now]
The button I want to add is the time_is_now, allowing the user to populate the time field with the current time.
I have tried updating custom/modules/Notes/metadata/quickcreatedefs.php with:
array (
'name' => 'billable_start_c',
'label' => 'LBL_BILLABLE_START',
'customCode' => '<button</button>',
)
But this replaces the input field with the custom code. I could just put in the stock code and then my custom code, but date fields use yui and a widget, so I'd prefer not to.
Is there anyway to do something like:
'customCode' => '{default} <button></button>',
so that the default code gets output and then the custom code?
You could create a new SugarField template, which will essentially allow you to create the markup for your field. If you named your SugarField TimeIsNow, you could create a field with that type (instead of text,int, date or whatever). You should take a look at some of the other SugarFields to see how they are formatted, but it's really just HTML. When the field is set to that type, it pulls in that HTML template. You can tie your JS to the onclick function. Sugar is very easy to customize, so I definitely wouldn't get in the habit of solving all your customization needs this way...It's another way to look at it though.
Don't use custom code if you can help it. Either copy over the tpl to custom/modules/[yourmodule]/tpls/[yourtemplate] and code the bitton in there or use an after_ui_frame hook and some js to insert you custom button into the DOM.