TYPO3将filemetadata添加到后端TCA IRRE元素

时间:2017-10-20 09:44:17

标签: typo3 fal

我想在tt_content(TYPO3 8.7中的标准IRRE字段)中为图像添加其他元数据(例如版权)。

我安装了“filemetadata”扩展来获取这些附加字段。如果我打开sys_file_reference,我可以访问这些字段。现在我想向tt_content IRRE“image”字段显示版权字段,该字段当前显示标准字段“title,description,link”。

我试图覆盖TCA(myExtension / Configuration / TCA / Override / tt_content.php):

'image' => [
    'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_general.xlf:LGL.images',
    'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', [
        'appearance' => [
            'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference'
        ],
        // custom configuration for displaying fields in the overlay/reference table
        // to use the imageoverlayPalette instead of the basicoverlayPalette
        'overrideChildTca' => [
            'types' => [
                '0' => [
                    'showitem' => 'copyright,
                            --palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                            --palette--;;filePalette'
                ],
                \TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
                    'showitem' => '
                            --palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                            --palette--;;filePalette'
                ],
                \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
                    'showitem' => '
                            --palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                            copyright,--palette--;;filePalette'
                ],
                \TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
                    'showitem' => '
                            --palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.audioOverlayPalette;audioOverlayPalette,
                            --palette--;;filePalette'
                ],
                \TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
                    'showitem' => '
                            --palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.videoOverlayPalette;videoOverlayPalette,
                            --palette--;;filePalette'
                ],
                \TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
                    'showitem' => '
                            --palette--;LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;imageoverlayPalette,
                            --palette--;;filePalette'
                ]
            ],
        ],
    ], $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
],

和myExtension的localconf一样:

$GLOBALS['TCA']['sys_file_reference']['types'] =[
        '0' => array('showitem' => 'uid_local,uid_foreign,tablenames,fieldname,title,description,copyright'),
];

但版权字段不会出现。 请帮忙。

2 个答案:

答案 0 :(得分:0)

$GLOBALS['TCA']['sys_file_reference']['ctrl']['types']

应该是

$GLOBALS['TCA']['sys_file_reference']['types']

不确定是否还有其他问题。

答案 1 :(得分:0)

我找到了一个肮脏的解决方案。 主要问题是,sys_file_metadata与sys_file_reference无关!

我解决了我的问题:

  1. TCA sys_file_reference中的新UserFunc用于设置新的调色板
  2. EXT:myext /配置/ TCA /覆盖/ sys_file_reference.php:

    $metaDataSysFileReferenceColumns = [
    'metadata' => array (
        'exclude' => 1,
        'label' => 'Metadata',
        'config' => array (
            'type' => 'user',
            'userFunc' => \VENDOR\MyExt\UserFunction\ProviderField::class . '->getMetaData',
        )
    

    )]; \ TYPO3 \ CMS \ Core \ Utility \ ExtensionManagementUtility :: addTCAcolumns('sys_file_reference',$ metaDataSysFileReferenceColumns); \ TYPO3 \ CMS \ Core \ Utility \ ExtensionManagementUtility :: addFieldsToPalette('sys_file_reference','metaPalette','metadata');

    1. Userfunction ProviderField-> getMetaData() public function getMetaData(array $ parameters,$ parentObject) {

          $uid = $parameters['row']['uid_local'][0]['uid'];
      
          $sys_language_uid = 0;
          if (!empty($parameters['row']['sys_language_uid'])) {
              $sys_language_uid = $parameters['row']['sys_language_uid'][0];
          }
      
          $queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
              ->getQueryBuilderForTable('sys_file_metadata');
          $recordInDatabase = $queryBuilder
              ->select('*')
              ->from('sys_file_metadata')
              ->where(
                  $queryBuilder->expr()->eq(
                      'file',
                      $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
                  ),
                  $queryBuilder->expr()->eq(
                      'sys_language_uid',
                      $queryBuilder->createNamedParameter($sys_language_uid, \PDO::PARAM_INT)
                  )
              )
              ->setMaxResults(1)
              ->execute()
              ->fetch();
      
      $html = array();
      $html[] = '
          <div class="row">
              <div class="form-group t3js-formengine-validation-marker t3js-formengine-palette-field col-sm-6">
                  <label class="t3js-formengine-label">
                      Creator
                  </label>
                  <div class="formengine-field-item t3js-formengine-field-item">
                      <div class="form-control-wrap" style="max-width: 480px">
                          <div class="form-wizards-wrap">
                              <div class="form-wizards-element">
                                  <div class="form-control-clearable">
                                      <input type="text" id="formengine-input-'.uniqid().'"
                                              class="form-control t3js-clearable hasDefaultValue"
                                              data-formengine-validation-rules="[{&quot;type&quot;:&quot;trim&quot;}]"
                                              data-formengine-input-params="{&quot;field&quot;:&quot;data[sys_file_metadata]['.$recordInDatabase['uid'].'][creator]&quot;,&quot;evalList&quot;:&quot;trim&quot;,&quot;is_in&quot;:&quot;&quot;}"
                                              data-formengine-input-name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][creator]"
                                              data-formengine-input-initialized="true">
                                      <button type="button" class="close" tabindex="-1" aria-hidden="true" style="display: none;">
                                          <span class="t3js-icon icon icon-size-small icon-state-default icon-actions-close" data-identifier="actions-close">
                                              <span class="icon-markup">
                                                  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
                                                      <path d="M11.9 5.5L9.4 8l2.5 2.5c.2.2.2.5 0 .7l-.7.7c-.2.2-.5.2-.7 0L8 9.4l-2.5 2.5c-.2.2-.5.2-.7 0l-.7-.7c-.2-.2-.2-.5 0-.7L6.6 8 4.1 5.5c-.2-.2-.2-.5 0-.7l.7-.7c.2-.2.5-.2.7 0L8 6.6l2.5-2.5c.2-.2.5-.2.7 0l.7.7c.2.2.2.5 0 .7z" class="icon-color"></path>
                                                  </svg>
                                              </span>
                                          </span>
                                      </button>
                                  </div>
                                  <input type="hidden" name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][creator]" value="'.$recordInDatabase['creator'].'">
                              </div>
                              <div class="form-wizards-items-aside">
                                  <div class="btn-group"></div>
                              </div>
                              <div class="form-wizards-items-bottom"></div>
                          </div>
                      </div>
                  </div>
              </div>
              <div class="form-group t3js-formengine-validation-marker t3js-formengine-palette-field col-sm-6">
                  <label class="t3js-formengine-label">
                      Source
                  </label>
                  <div class="formengine-field-item t3js-formengine-field-item">
                      <div class="form-control-wrap" style="max-width: 480px">
                          <div class="form-wizards-wrap">
                              <div class="form-wizards-element">
                                  <div class="form-control-clearable">
                                      <input type="text" id="formengine-input-'.uniqid().'"
                                              class="form-control t3js-clearable hasDefaultValue"
                                              data-formengine-validation-rules="[{&quot;type&quot;:&quot;trim&quot;}]"
                                              data-formengine-input-params="{&quot;field&quot;:&quot;data[sys_file_metadata]['.$recordInDatabase['uid'].'][source]&quot;,&quot;evalList&quot;:&quot;trim&quot;,&quot;is_in&quot;:&quot;&quot;}"
                                              data-formengine-input-name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][source]"
                                              data-formengine-input-initialized="true">
                                      <button type="button" class="close" tabindex="-1" aria-hidden="true" style="display: none;">
                                          <span class="t3js-icon icon icon-size-small icon-state-default icon-actions-close" data-identifier="actions-close">
                                              <span class="icon-markup">
                                                  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
                                                      <path d="M11.9 5.5L9.4 8l2.5 2.5c.2.2.2.5 0 .7l-.7.7c-.2.2-.5.2-.7 0L8 9.4l-2.5 2.5c-.2.2-.5.2-.7 0l-.7-.7c-.2-.2-.2-.5 0-.7L6.6 8 4.1 5.5c-.2-.2-.2-.5 0-.7l.7-.7c.2-.2.5-.2.7 0L8 6.6l2.5-2.5c.2-.2.5-.2.7 0l.7.7c.2.2.2.5 0 .7z" class="icon-color"></path>
                                                  </svg>
                                              </span>
                                          </span>
                                      </button>
                                  </div>
                                  <input type="hidden" name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][source]" value="'.$recordInDatabase['source'].'">
                              </div>
                              <div class="form-wizards-items-aside">
                                  <div class="btn-group"></div>
                              </div>
                              <div class="form-wizards-items-bottom"></div>
                          </div>
                      </div>
                  </div>
              </div>
              <div class="form-group t3js-formengine-validation-marker t3js-formengine-palette-field col-sm-6">
                  <label class="t3js-formengine-label">
                      Copyright
                  </label>
                  <div class="formengine-field-item t3js-formengine-field-item">
                      <div class="form-control-wrap" style="max-width: 480px">
                          <div class="form-wizards-wrap">
                              <div class="form-wizards-element">
                                  <div class="form-control-clearable">
                                      <input type="text" id="formengine-input-'.uniqid().'"
                                              class="form-control t3js-clearable hasDefaultValue"
                                              data-formengine-validation-rules="[{&quot;type&quot;:&quot;trim&quot;}]"
                                              data-formengine-input-params="{&quot;field&quot;:&quot;data[sys_file_metadata]['.$recordInDatabase['uid'].'][copyright]&quot;,&quot;evalList&quot;:&quot;trim&quot;,&quot;is_in&quot;:&quot;&quot;}"
                                              data-formengine-input-name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][copyright]"
                                              data-formengine-input-initialized="true">
                                      <button type="button" class="close" tabindex="-1" aria-hidden="true" style="display: none;">
                                          <span class="t3js-icon icon icon-size-small icon-state-default icon-actions-close" data-identifier="actions-close">
                                              <span class="icon-markup">
                                                  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
                                                      <path d="M11.9 5.5L9.4 8l2.5 2.5c.2.2.2.5 0 .7l-.7.7c-.2.2-.5.2-.7 0L8 9.4l-2.5 2.5c-.2.2-.5.2-.7 0l-.7-.7c-.2-.2-.2-.5 0-.7L6.6 8 4.1 5.5c-.2-.2-.2-.5 0-.7l.7-.7c.2-.2.5-.2.7 0L8 6.6l2.5-2.5c.2-.2.5-.2.7 0l.7.7c.2.2.2.5 0 .7z" class="icon-color"></path>
                                                  </svg>
                                              </span>
                                          </span>
                                      </button>
                                  </div>
                                  <input type="hidden" name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][copyright]" value="'.$recordInDatabase['copyright'].'">
                              </div>
                              <div class="form-wizards-items-aside">
                                  <div class="btn-group"></div>
                              </div>
                              <div class="form-wizards-items-bottom"></div>
                          </div>
                      </div>
                  </div>
              </div>
              <div class="form-group t3js-formengine-validation-marker t3js-formengine-palette-field col-sm-6">
                  <label class="t3js-formengine-label">
                      Publisher
                  </label>
                  <div class="formengine-field-item t3js-formengine-field-item">
                      <div class="form-control-wrap" style="max-width: 480px">
                          <div class="form-wizards-wrap">
                              <div class="form-wizards-element">
                                  <div class="form-control-clearable">
                                      <input type="text" id="formengine-input-'.uniqid().'"
                                              class="form-control t3js-clearable hasDefaultValue"
                                              data-formengine-validation-rules="[{&quot;type&quot;:&quot;trim&quot;}]"
                                              data-formengine-input-params="{&quot;field&quot;:&quot;data[sys_file_metadata]['.$recordInDatabase['uid'].'][publisher]&quot;,&quot;evalList&quot;:&quot;trim&quot;,&quot;is_in&quot;:&quot;&quot;}"
                                              data-formengine-input-name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][publisher]"
                                              data-formengine-input-initialized="true">
                                      <button type="button" class="close" tabindex="-1" aria-hidden="true" style="display: none;">
                                          <span class="t3js-icon icon icon-size-small icon-state-default icon-actions-close" data-identifier="actions-close">
                                              <span class="icon-markup">
                                                  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
                                                      <path d="M11.9 5.5L9.4 8l2.5 2.5c.2.2.2.5 0 .7l-.7.7c-.2.2-.5.2-.7 0L8 9.4l-2.5 2.5c-.2.2-.5.2-.7 0l-.7-.7c-.2-.2-.2-.5 0-.7L6.6 8 4.1 5.5c-.2-.2-.2-.5 0-.7l.7-.7c.2-.2.5-.2.7 0L8 6.6l2.5-2.5c.2-.2.5-.2.7 0l.7.7c.2.2.2.5 0 .7z" class="icon-color"></path>
                                                  </svg>
                                              </span>
                                          </span>
                                      </button>
                                  </div>
                                  <input type="hidden" name="data[sys_file_metadata]['.$recordInDatabase['uid'].'][publisher]" value="'.$recordInDatabase['publisher'].'">
                              </div>
                              <div class="form-wizards-items-aside">
                                  <div class="btn-group"></div>
                              </div>
                              <div class="form-wizards-items-bottom"></div>
                          </div>
                      </div>
                  </div>
              </div>
          </div>';
      return implode(LF, $html);
      

      }

    2. 最后一步覆盖tt_content中的资产(FileReference): EXT:myext /配置/ TCA /覆盖/ tt_content.php: 'assets'=&gt; [     'label'=&gt; 'LLL:EXT:前端/资源/私人/语言/ Database.xlf:tt_content.asset_references',     'config'=&gt; \ TYPO3 \ CMS \ Core \ Utility \ ExtensionManagementUtility :: getFileFieldTCAConfig('assets',[         'appearance'=&gt; [             'createNewRelationLinkTitle'=&gt; 'LLL:EXT:前端/资源/私人/语言/ Database.xlf:tt_content.asset_references.addFileReference'         ]         //用于在叠加/引用表中显示字段的自定义配置         'overrideChildTca'=&gt; [             'types'=&gt; [                 '0'=&gt; [                     'showitem'=&gt; “                     --palette - ; LLL:EXT:朗/ locallang_tca.xlf:sys_file_reference.imageoverlayPalette; metaPalette,                     --palette - ;; imageoverlayPalette,                     --palette - ;; filePalette”                 ]                 \ TYPO3 \ CMS \ Core \ Resource \ File :: FILETYPE_TEXT =&gt; [                     'showitem'=&gt; “                     --palette - ; LLL:EXT:朗/ locallang_tca.xlf:sys_file_reference.imageoverlayPalette; metaPalette,                     --palette - ;; imageoverlayPalette,                     --palette - ;; filePalette”                 ]                 \ TYPO3 \ CMS \ Core \ Resource \ File :: FILETYPE_IMAGE =&gt; [                     'showitem'=&gt; “                     --palette - ; LLL:EXT:朗/ locallang_tca.xlf:sys_file_reference.imageoverlayPalette; metaPalette,                     --palette - ;; imageoverlayPalette,                     --palette - ;; filePalette”                 ]                 \ TYPO3 \ CMS \ Core \ Resource \ File :: FILETYPE_AUDIO =&gt; [                     'showitem'=&gt; “                     --palette - ; LLL:EXT:朗/ locallang_tca.xlf:sys_file_reference.imageoverlayPalette; metaPalette,                     --palette - ;; imageoverlayPalette,                     --palette - ;; filePalette”                 ]                 \ TYPO3 \ CMS \ Core \ Resource \ File :: FILETYPE_VIDEO =&gt; [                     'showitem'=&gt; “                     --palette - ; LLL:EXT:朗/ locallang_tca.xlf:sys_file_reference.imageoverlayPalette; metaPalette,                     --palette - ;; imageoverlayPalette,                     --palette - ;; filePalette”                 ]                 \ TYPO3 \ CMS \ Core \ Resource \ File :: FILETYPE_APPLICATION =&gt; [                     'showitem'=&gt; “                     --palette - ; LLL:EXT:朗/ locallang_tca.xlf:sys_file_reference.imageoverlayPalette; newsPalette,                     --palette - ;; imageoverlayPalette,                     --palette - ;; filePalette”                 ]             ]         ]     ],$ GLOBALS ['TYPO3_CONF_VARS'] ['SYS'] ['mediafile_ext']) ],

    3. Voila,tt_content中的每个媒体元素都会显示有关折叠IRRE的其他元数据信息。我知道,这真的很脏......