Hey,

ich hab kürzlich den Hyperlink um einen Icon erweitern müssen, sowie um eine Checkbox um eine Hintergrundfarbe zu aktivieren und wollte euch das zur Verfügung stellen.

Erst gehts in eure Datei für die DCA-Anpassungen:
PHP-Code:
// Hyperlink: Upload-Feld für Icons
PaletteManipulator::create()
    ->
addField('icon_upload''link_legend'PaletteManipulator::POSITION_APPEND)
    ->
addField('hyperlink_background''link_legend'PaletteManipulator::POSITION_APPEND)
    ->
applyToPalette('hyperlink''tl_content')

Das Feld für den Upload anlegen:
PHP-Code:
$GLOBALS['TL_DCA']['tl_content']['fields']['icon_upload'] = array(
    
'label' => &$GLOBALS['TL_LANG']['tl_content']['singleSRC'],
    
'exclude' => true,
    
'inputType' => 'fileTree',
    
'filesOnly' => true,
    
'extensions' => 'jpg,jpeg,png,webp,svg',
    
'eval' => array('filesOnly' => true'fieldType' => 'radio''mandatory' => false'tl_class' => 'clr'),
    
'load_callback' => array
    (
        array(
'tl_content''setSingleSrcFlags')
    ),
    
'sql' => "binary(16) NULL",
); 
Das Feld für die Checkbox anlegen:
PHP-Code:
$GLOBALS['TL_DCA']['tl_content']['fields']['hyperlink_background'] = array(
    
'label' => &$GLOBALS['TL_LANG']['tl_content']['hyperlink_background'],
    
'exclude' => true,
    
'inputType' => 'checkbox',
    
'eval' => array('tl_class' => 'w50 clr'),
    
'sql' => "char(1) NOT NULL default ''",
); 

im ce_hyperlink.html5:
PHP-Code:
<?php if ($this->icon_upload): ?>
              <?php if (!empty($this->icon_upload))  {
                  echo 
'<figure class="image_container hyperlink-icon">';
                  
$imgpath FilesModel::findByPk($this->icon_upload)->path;
                  
$picture Picture::create($imgpath41)->getTemplateData();
                  echo 
$this->insert('picture_default'$picture);
                  echo 
'</figure>';
              }
              
?>
        <?php endif; ?>
und wenn ihr noch Klassen bei gesetzter Checkbox vergeben wollt, an beliebiger sinnvoller Stelle:
PHP-Code:
<?php if ($this->hyperlink_background): ?> u-bg-grey<?php endif; ?><?php if ($this->icon_upload): ?> hyperlink-icon-box<?php endif; ?>
Falls jemand noch eine modernere Art hat, das Icon im Template auszugeben, gerne her damit