Extbase: get/save specific language of object - typo3

In a CommandController, I need to sync objects with an external source. The source is multi-language and shall be mapped to localized records in Typo3.
I just seem too blind to find options to ...
a) get records in a specific language
b) add/update records in a specific language
... (from a CommandController context).
I was expecting this to be a function of the model (AbstractEntity) or maybe the repository, but could not find any public lang/sys_lang/localize-functions there.
(Typo3 version 6.2)

You can write a method in your repository class to get all records with the sys_language_uid you need and use that method to get all the records.
If you model does not have the sys_language_uid, add it so you can use it in your controller.
(if your model has sys_laguage_uid, you can use $yourrepo->findBySysLanguageUid(1) )
Probably you need to change the defaultQuerySettings so you can retrieve the any language, regarding the site language (if you are using a FE ext)
adding the records with a specific language is $yourobject->setSysLangUid(1); (or whatever lang id)

Related

Typo3 9.5 : Add a new field to a new page type

I make a new page type with the help of this doc : https://docs.typo3.org/m/typo3/reference-coreapi/9.5/en-us/ApiOverview/PageTypes/
I want now to customize it by adding a new field to my page
For example a field under "title" field
I checked the doc and didn't find how to do this
Some one can explain me how to custom my new page please?
Thanks
extending pages records is the same than extending tt_contentrecords.
there is a an example to this in the documentation: extend tt_content and use data processing.
This link is to the documentation of TYPO3 11 as this version is state of the art and gets support. For older versions the declarations may vary a little, but the concept is the same:
add new fields in database and TCA.
create a variant (type) and declare which fields should be shown for this variant.
you may need additional getter and setter or controller for this variant

How to disable Edit/Hide/Delete in TCA for TYPO3 Extbase Domain Model?

As the title already says, I want to make a specific Extbase domain-model completely "read only" .. It is a custom Log-Entry model that shall be viewable but must not be modified via backend (they are being generated during certain controller actions).
I do not use the TYPO3 log system intentionally, because I want to have a separate log with its own db-table etc.
I do know about the readOnly property for columns, but I`d like to disable any modification-functions in the list view also.
Thanks in advance, Oliver
There's not only option "readOnly" for columns, this option can also be set for the whole table:
$GLOBALS['TCA']['yourTable']['ctrl']['readOnly'] = 1;
Have a look at EXT:static_info_tables, the records from this extension are not editable.

Extbase looking for wrong table

I'm using TYPO3 7.4.0 and I'm learning to build extensions in extbase & fluid.
I have a vendor prefix in my table names. I create three tables for my extensions. When I go in the backend and add entities in the list view on the resource folder I created, it works without any problems. When I go to the Frontend to view the index action of my entity it looks for a table without the vendor prefix in it's name. Does anyone know what that means? I create the tables in the "ext_tables.sql". I have no table mapping defined. I don't know where to change which tables extbase is looking for.
By default Extbase looks for table using schema tx_extkey_domain_model_modelname, so for Animal model in zoo ext it will be tx_zoo_domain_model_animal. (extkey without underscore if any!)
If you used other schema (like vendor name within table name) you need to use mapping. I.e. create file ext_typoscript_setup.txt in main folder of your ext and use this:
config.tx_extbase{
persistence{
classes{
Vendor\Zoo\Domain\Model\Animal {
mapping {
tableName = tx_your_own_name
}
}
}
}
}
BTW: it's best idea to keep the original naming schema. Other thing is that creating extensions manually can be tricky - at least for beginners, install Extension Builder ext to fast kickstart new extensions just with click-click way.

How to use Entity, Mapper, Service and Hydrator in ZF2

I am making a ZF2 app. I am using entities, mappers and services (e.g. UserEntity, UserMapper, UserService) to manage the objects/models. Properties in the entities are CamalCased (e.g. FirstName, LastName) while in the database, fields are using underscore (first_name, last_name). I will plan to use a hydrator to map the properties and db-fields when retrieving or saving. The service object (UserService) will be used to communicate with the mapper to retrieve and save data models using the mapper. The hydrator will convert the result of mapper and convert them into proper entities.
The thing I am confused is that when the service (UserService) need to provide some cirteria - for example to find all users with a specific 'last name', will the service use the database field names (last_name) or entity properties name (LastName)?
If the db field name is used in the Service, so any change in the db structure will require me to update the service also, which completely fails the reason of using the whole approach.
If you take a look at the ClassMethods:hydrate method (https://github.com/zendframework/zf2/blob/master/library/Zend/Stdlib/Hydrator/ClassMethods.php) you will see that it just copies the properties from one object to another. You have the option of converting the property names to/from camelCase but that's it.
If you change a column name in your database then you will need to change corresponding property name in your object. And vice versa. Which I believe is the crux of your question?
If you want to make table column names be independent of your method names then you need something that lets you define an actual mapping table somewhere. Change a column or method name and you only need to update the configuration mapping table.
Not a ZF2 expert so I could be wrong but it doesn't look like any of the supplied hydrators support this.
I do know that Doctrine 2 supports it.

How to Query a Read-Only Field with ORMLite

I am trying ORMLite as an ORM for a project I am developing. I am mapping a java class to a table that has some auditing fields (ie. updatedby, updatedtime, etc.). The auditing fields are maintained by the database using triggers to ensure that no matter what front-end the user is using these fields will always be correctly updated when a record is updated.
I need to include these fields in my client application to inform the user when the record was last updated, but the user can't change them. Is there a way to annotate the class so that ORMLite won't try to perform updates on these fields or include them in insert statements. The database will deny an update if these fields are included in an update statement (which is why I can't just write back the original value that was queried from the database).
I tried using the #DatabaseField(persisted = false) annotation on the Java fields, but then they don't get queried at all so the Java object is never populated with these fields.
Basically, I need these fields to be included in SELECT statements, but not included in INSERT or UPDATE statements (equivalent to a #DatabaseField(immutable = true) annotation).
Interesting pattern. ORMLite didn't support the feature at the time but now it does as of version 4.46.
There is now a #DatabaseField(readOnly=true) annotation field.