pdir / social-feed-bundle

Social feed extension for Contao CMS
GNU Lesser General Public License v3.0
13 stars 13 forks source link

Bug: Your extension overwrites the meta fields in tl_news #61

Closed jankout closed 2 years ago

jankout commented 2 years ago

Bug description

Your extension overwrites the meta fields in tl_news in Contao 4.11.x

Following fields disappear if I use your extension

_{meta_legend}, pageTitle, robots, description, serpPreview_

it would be better to use Contao\CoreBundle\DataContainer\PaletteManipulator;

jankout commented 2 years ago

Your _tlnews.php could be like this

<?php
use Contao\CoreBundle\DataContainer\PaletteManipulator;
/**
 * add global operation
 */
array_insert($GLOBALS['TL_DCA']['tl_news']['list']['global_operations'], 0, [
    'sf_moderate' => [
        'label' => &$GLOBALS['TL_LANG']['tl_news']['sf_moderate'],
        'href' => 'key=moderate',
        'class' => 'header_new header_sf_moderate',
        'attributes' => 'onclick="Backend.getScrollOffset()"',
        #'button_callback' => ''
    ],
]);

/**
 * Add palette to tl_module
 */

$GLOBALS['TL_DCA']['tl_news']['fields']['social_feed_id'] = array
(
    'label' => &$GLOBALS['TL_LANG']['tl_news']['social_feed_id'],
    'exclude' => true,
    'inputType' => 'text',
    'eval' => array(
        'mandatory'=>false,
        'tl_class' => 'w50',
        'decodeEntities' => true,
    ),
    'sql' => "varchar(128) NOT NULL default ''",
);

$GLOBALS['TL_DCA']['tl_news']['fields']['social_feed_type'] = array
(
    'label' => &$GLOBALS['TL_LANG']['tl_news']['social_feed_type'],
    'exclude'                 => true,
    'filter'                  => true,
    'sorting'                 => true,
    'inputType'               => 'select',
    'options'                 => array('Facebook','Instagram','Twitter'),
    'eval'                    => array('includeBlankOption'=>true, 'tl_class'=>'w50'),
    'sql'                     => "varchar(255) NOT NULL default ''"
);

$GLOBALS['TL_DCA']['tl_news']['fields']['social_feed_account'] = array
(
    'label' => &$GLOBALS['TL_LANG']['tl_news']['social_feed_account'],
    'exclude' => true,
    'inputType' => 'text',
    'eval' => array(
        'mandatory'=>false,
        'tl_class' => 'w50',
        'decodeEntities' => true,
    ),
    'sql' => "varchar(128) NOT NULL default ''",
);

$GLOBALS['TL_DCA']['tl_news']['fields']['social_feed_account_picture'] = array
(
    'label' => &$GLOBALS['TL_LANG']['tl_news']['social_feed_account_picture'],
    'exclude' => true,
    'inputType' => 'fileTree',
    'eval' => array( 'filesOnly'=>true, 'fieldType'=>'radio', 'feEditable'=>true, 'feViewable'=>true, 'feGroup'=>'personal', 'tl_class'=>'w50 autoheight' ),
    'load_callback' => array
    (
        array('tl_news_socialfeed', 'setSingleSrcFlags')
    ),
    'sql' => "binary(16) NULL"
);

$GLOBALS['TL_DCA']['tl_news']['fields']['social_feed_config'] = array
(
    'label' => &$GLOBALS['TL_LANG']['tl_news']['social_feed_config'],
    'exclude' => true,
    'inputType' => 'text',
    'eval' => array(
        'mandatory'=>false,
        'tl_class' => 'w50',
        'readonly'=>'readonly'
    ),
    'sql' => "int(10) unsigned NULL",
);

class tl_news_socialfeed extends Backend
{
    /**
     * Dynamically add flags to the "singleSRC" field
     *
     * @param mixed         $varValue
     * @param DataContainer $dc
     *
     * @return mixed
     */
    public function setSingleSrcFlags($varValue, DataContainer $dc)
    {
        if ($dc->activeRecord)
        {
            switch ($dc->activeRecord->type)
            {
                case 'text':
                case 'hyperlink':
                case 'image':
                case 'accordionSingle':
                    $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['extensions'] = Config::get('validImageTypes');
                    break;
                case 'download':
                    $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['extensions'] = Config::get('allowedDownload');
                    break;
            }
        }
        return $varValue;
    }
}
PaletteManipulator::create()
    ->addLegend('pdir_sf_settings_legend', 'publish_legend', PaletteManipulator::POSITION_AFTER)
    ->addField('social_feed_type', 'pdir_sf_settings_legend', PaletteManipulator::POSITION_APPEND)
    ->addField('social_feed_id', 'social_feed_type', PaletteManipulator::POSITION_AFTER)
    ->addField('social_feed_account', 'social_feed_id', PaletteManipulator::POSITION_AFTER)
    ->addField('social_feed_account_picture', 'social_feed_account', PaletteManipulator::POSITION_AFTER)
    ->applyToPalette('default', 'tl_news')
    ->applyToPalette('article', 'tl_news')
    ->applyToPalette('external', 'tl_news')
    ->applyToPalette('internal', 'tl_news')
; 
MDevster commented 2 years ago

fixed in version 2.9.0