0

I clicked me a little extension in the Extension Builder together. It is a general object (wall) with IRRE-elements (windows in the wall - 1:n). This IRRE-element has an select-box (window-color) with different values. I added the values in the Override-folder, so they don't become overwritten when I add another field in the Extension Builder.

In my template I loop through all n elements and try to output each one in a partial. But now in the browser there are only the IDs displayed ant not the values.

Here is my TCA-Override:

$GLOBALS['TCA']['MY_EXTENSIO']['columns']['color']['config']['items'] = [
['Green', 0],
['Red', 1],
['Blue', 2],
['Gray with orange dots', 3],
];

The way I render it in the partial

{window.color} // window  is the passed variable of the loop

In the backend everything works just fine. Even if I save data, reload... There is always the name of the color (e.g. "Blue") selected. But in the frontend the output is simply "2" - the ID of the color. I did not anything else: rather I changed the controller nor I worked multilangue...

Does anybody of you have clue for me? I'am googling since hours without any result.

Daniel
  • 6,916
  • 2
  • 36
  • 47
user1508609
  • 71
  • 10
  • 1
    Your TCA configuration will show select box in BE, therefore you saved from BE it'll save value of select box as you given 2 for Blue. You can give value something like ['Blue'=>'#00F'] and need to check your DB 'color' field type is varchar or numeric. in this case you need your DB field type varchar. – Ghanshyam Gohel Jul 17 '16 at 15:44
  • How did the TCA field config look like before the override? Can you post it here? – Jozef Spisiak Jul 17 '16 at 19:35
  • @Ghanshyam Gohel, I changed the code, as you suggested, but now it is impossible to save an entry in the backend. There occurs an error every time: " 1: These fields of record 3 in table "tx_hous_domain_model_window" have not been saved correctly: color! The values might have changed due to type casting of the database." Is there a way to change the database? – user1508609 Jul 19 '16 at 14:06

1 Answers1

1

TCA-Override:

$GLOBALS['TCA']['MY_EXTENSIO']['columns']['color']['config']['items'] = [
['Green', '#060'],
['Red', '#F00'],
['Blue', '#00F'], // for better practice I suggest classes like: ['Blue', 'blue-color-code']
['Gray with orange dots', '#999'],
];

Change field type in ext_tables.sql -> donot forget to update DB from install tool

CREATE TABLE tx_hous_domain_model_window (
   color varchar(255) DEFAULT '' NOT NULL
);

Just have a look your model should be look like:

class Window extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
   protected $color = '';

   public function getColor() {
        return $this->color;
   }
   public function setColor($color) {
        $this->color = $color;
   }
}

in your view:

{window.color} <!-- either you'll get '#00F' for blue or 'blue-color-code' class as per your TCA config -->

Donot forget to clear install tool cache

Ghanshyam Gohel
  • 1,264
  • 1
  • 17
  • 27
  • is that the best way? – Sebastian Sep 21 '16 at 10:54
  • @SebastianSchmal as there're many way to achieve what you need but always depend on requirement. generally I prefer or suggest to used classes as I gave it in above example. http://screencast.com/t/8OXXVRBGu – Ghanshyam Gohel Sep 21 '16 at 12:06
  • @SebastianSchmal as pointed already there are different ways. I'd suggest to use a domain model for Color as well. You can then decide whether it shall be a ValueObject or a DomainEntity - if the behavior is only bound to the attributes (RGB-values, CYMK-values, ..) it's basically a ValueObject – Oliver Hader Oct 10 '16 at 14:01