0

I needed a new field "json" for my extension, so I've added the new field "json" (mediumtext) to the database, then I've added the following code to my Model:

/**
 * json
 *
 * @var string
 */
protected $json = '';

/**
 * Returns the json
 *
 * @return string $json
 */
public function getJson()
{
    return $this->json;
}

/**
 * Sets the json
 *
 * @param string $json
 * @return void
 */
public function setJson($json)
{
    $this->json = $json;
}

But when I set the property with $myObject->setJson("12345678910") and add the object to the repository and persist it

$this->myObjectRepository->add($myObject);
$this->persistenceManager->persistAll();

All other properties saved, except the json property (setter is called).

I also tried to map the property to the database field in typoscript:

plugin.tx_menopur {

persistence {
  classes {
    Company\Extension\Domain\Model\MyModel {
      mapping {
        tableName = tx_extension_domain_model_mymodel
        recordType = \Company\Extension\Domain\Model\MyModel
        columns {
          json.mapOnProperty = json
        }
      }
    }  
  }
}
}
Ralf
  • 836
  • 1
  • 9
  • 32
  • 1
    yes, "clear all cache" at install tool, "clear all caches" in typo3, reinstalled the extension – Ralf Mar 09 '18 at 08:24
  • Did you update the `TCA` of your extension as well? – insertusernamehere Mar 09 '18 at 08:28
  • You don't need the `mapOnProperty` here since it will work automatically for this case. You only need this if either DB field (snail_case) or model property (lowerCamelCase) do not follow the usual naming conventions. – Mathias Brodala Mar 09 '18 at 08:31
  • No because I only need the field in code and another problem is, that I'm using the extension builder for this extension too, but there I could't add the field with database type mediumtext (text is too small). And if I change something in the future width my extension builder, the tca would be overriden. – Ralf Mar 09 '18 at 08:33
  • So the problem is not added the field to the tca right? – Ralf Mar 09 '18 at 08:34
  • Maybe this is intersting/connected too: https://stackoverflow.com/questions/27274477/parse-an-existing-json-string-in-fluid-template/27278391 – Urs Mar 10 '18 at 06:53

2 Answers2

0

Thank you insertusernamehere for the TCA hint. Now I added tx_company_domain_model_mymodel.php in ...Configuration/TCA/Overrides/ with the following content:

## EXTENSION BUILDER DEFAULTS END TOKEN - Everything BEFORE this line is overwritten with the defaults of the extension builder

if (!defined('TYPO3_MODE')) {
    die ('Access denied.');
}

$temporaryColumns = array (
    'json' => array (
            'exclude' => 0,
            'label' => 'Json',
            'config' => array (
                    'type' => 'text',
            )
    ),
);

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
    'tx_extension_domain_model_mymodel',
    $temporaryColumns
);

Thanks!

Ralf
  • 836
  • 1
  • 9
  • 32
0

For add new property in extbase extension. You need to update below three files.

  • ext_tables.spl
  • Configuration/TCA/tx_extension_key_domain_model_model.php
  • Classes/Domain/Model/model_anme.php

Your model configuration is correct. Please add below configuration if not added.

For ext_tables.spl

#
# Table structure for table 'tx_extension_key_domain_model_model'
#
CREATE TABLE tx_extension_key_domain_model_model (
   json varchar(255) DEFAULT '' NOT NULL,
)

Your TCA configuration looks like below.

'json' => array(
    'exclude' => 0,
    'label' => 'title',
    'config' => array(
        'type' => 'input',
        'size' => 30,
        'eval' => 'trim'
    ),
),
Pravin Vavadiya
  • 3,195
  • 1
  • 17
  • 34