TCA override on showItem when sys_language_uid != 0 - php

I'm updating a TYPO3 v8.7 to TYPO3 10.4 LTS
In the TCA we have a pageType with a showitem of our choice. In v8 we used the following to have a custom view for a translated page eg. pages_language_overlay
$GLOBALS['TCA']['pages_language_overlay']['types'][$doktype] = array_replace_recursive(
$GLOBALS['TCA']['pages_language_overlay']['types'][$doktype],
[
'showitem' => '
myCustomShowItemString
'
]
);
Question: What would be the correct way to get have this behaviour again since pages_language_overlay does not exist anymore?

as the translated pagesrecords also are pages records you need this configuration for the table pages.
either you have it already, as your new doktype behaves the same for each language
or you need a special handling if sys_language_uid is not 0.
Then you probably need display conditions for those fields which behave different depending on sys_language_uid (this one visible, others invisible?)

TCA - file which has to be loaded after custom fields
$disableOnLanguageOverlay = [
'my_tca_field',
'my_tca_field',
];
foreach ($disableOnLanguageOverlay as $field) {
if (isset($GLOBALS['TCA']['pages']['columns'][$field])) {
$GLOBALS['TCA']['pages']['columns'][$field] = array_merge($GLOBALS['TCA']['pages']['columns'][$field], ['l10n_mode' => 'exclude']);
}
}
And for Typoscript
[siteLanguage("languageId") != 0]
TCEFORM {
pages {
myField {
disabled = 0
}
}
}
[global]
Solved above

Related

TYPO3: Override TCA backend class public variables from another extension

I'm using the tx_news extension for Typo3. Therefore I'd like to disable some settings that are not used on my page, for instance categories:
I've already disabled them in the PageTS for the records like this:
TCEFORM {
tx_news_domain_model_news {
categories.disabled = 1
}
}
Removed them from the administration filters and columns:
tx_news {
module {
columns = istopnews,datetime,author
filters {
categories = 0
categoryConjunction = 0
includeSubCategories = 0
}
}
}
Now I'd also like to disable them in the plugin settings when adding the plugin to the page. in the BackendUtility.php I found the following lines who will do that for me (notice I've added categories categoryConjunction,..):
public $removedFieldsInListView = [
'sDEF' => 'dateField,singleNews,previewHiddenRecords,selectedList,categories,categoryConjunction,includeSubCategories',
'additional' => '',
'template' => ''
];
Of course like this I've already disabled the categories, but by directly editing the extension instead of overriding it from my own extension, that means when I update tx_news I will lose that configuration.
What $GLOBALS[TCA].. stuff do I have to add to get the same result? I can't find anything in the backend debugging...
I'm searching something like (or some TypoScript stuff if possible):
$GLOBALS['TCA']['tx_news_domain_model_news']['plugin']['backendUtility'][removeFieldsInListView]= 'bla, blabla, bla';
I appreciate all the help!
Have you tried some TsConfig like that
TCEFORM {
tt_content {
pi_flexform {
news_pi1 {
sDEF {
# Important is the escaping of the dot which is part of the fieldname
settings\.orderBy.disabled = 1
}
}
}
}
}

SilverStripe default content author permissions

The default value for Manage site configuration is off
security > groups > content authors > permissions
Although it's possible to simply check the box and activate this, I would rather have this on by default for every SS installation.
How can the default value for this be set to on?
This should do as required, make an extension of Group and add a requireDefaultRecords function, this is called on every dev build.
This function is to look for that permission and if not existing create it...
class GroupExtension extends DataExtension {
function requireDefaultRecords() {
//get the content-authors group
if ($group = Group::get()->filter('Code','content-authors')->first()) {
//expected permission record content
$arrPermissionData = array(
'Arg' => 0,
'Type' => 1,
'Code' => 'EDIT_SITECONFIG',
'GroupID' => $group->ID
);
//if the permission is not found, then create it
if (!Permission::get()->filter($arrPermissionData)->first())
Permission::create($arrPermissionData)->write();
}
}
}
As ever to register the extension add this to your config.yml...
Group:
extensions:
- GroupExtension

Left column not appearing on custom page/controller

I've created a custom page devis and its controller in Prestashop 1.6, but I'm unable to display any columns.
Controller :
class DevisController extends FrontController
{
public $php_self = 'devis';
public $display_column_left = true;
...
}
In Theme configuration, my 'Devis' page appears and the left column is checked :
The "display or not" logic happens in FrontController.php's constructor :
if (isset($this->php_self) && is_object(Context::getContext()->theme)) {
$columns = Context::getContext()->theme->hasColumns($this->php_self);
// Don't use theme tables if not configured in DB
if ($columns) {
$this->display_column_left = $columns['left_column']; // FALSE : why ?
$this->display_column_right = $columns['right_column'];
}
}
I can force the column to display by doing $this->display_column_left = true but it's obviously not the way to do it.
Does someone know why $columns['left_column'] is false ?
Sh*t...
As mentionned by #julien-lachal, the issue was shop-level related.
That means I was browsing the dashboard as "All the shops".
By choosing the desired shop, the left column in theme settings was actually disabled.
Big problems simple fixes...

Trying to highlight current menu item in Drupal 8 using hook_preprocess_menu

I have the below function to create active trail functionality. So if I were to have /blog as a "parent" and a post of /blog/mypost, when on mypost the blog link would show as highlighted. I don't want to have to make menu items for all the blog posts. The problem is when caching is turned on (not using settings.local.php and debug turned off) the getRequestUri isn't changing on some pages. It seems to be cached depending on the page. It works fine with page caching turned off but I'd like to get this working with caching. Is there a better way to check for the current path and apply the active class?
function mytheme_preprocess_menu(&$variables, $hook) {
if($variables['theme_hook_original'] == 'menu__main'){
$node = \Drupal::routeMatch()->getParameter('node');
if($node){
$current_path = \Drupal::request()->getRequestUri();
$items = $variables['items'];
foreach ($items as $key => $item) {
// If current path starts with a part of another path i.e. a parent, set active to li.
if (0 === strpos($current_path, $item['url']->toString())) {
// Add active link.
$variables['items'][$key]['attributes']['class'] .= ' menu-item--active-trail';
}
}
}
}
}
I've also tried putting this into a module to try and see if I can get the current path to then do the twig logic in the menu--main.twig.html template but I have the same problem.
function highlight_menu_sections_template_preprocess_default_variables_alter(&$variables) {
$variables['current_path'] = $_SERVER['REQUEST_URI'];
}
After a very long time trying all sorts of things, I found an excellent module which addresses exactly this problem. Install and go, not configuration, it just works:
https://www.drupal.org/project/menu_trail_by_path
Stable versions for D7 and D8.
I tried declaring an active path as part of a custom menu block, and even then my declared trail gets cached. Assuming it's related to the "There is no way to set the active link - override the service if you need more control." statement in this changelog, though why MenuTreeParameters->setActiveTrail() exists is anybody's guess.
For the curious (and for me when I search for this later!), here's my block's build() function:
public function build() {
$menu_tree = \Drupal::menuTree();
$parameters = new MenuTreeParameters();
$parameters->setRoot('menu_link_content:700c69e6-785b-4db7-be49-73188b47b5a3')->setMinDepth(1)->setMaxDepth(1)->onlyEnabledLinks();
// An array of routes and menu_link_content ids to set as active
$define_active_mlid = array(
'view.press_releases.page_1' => 385
);
$route_name = \Drupal::request()->get(RouteObjectInterface::ROUTE_NAME);
if (array_key_exists($route_name, $define_active_mlid)) {
$menu_link = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(array('id' => $define_active_mlid[$route_name]));
$link = array_shift($menu_link);
$parameters->setActiveTrail(array('menu_link_content:' . $link->uuid()));
}
$footer_tree = $menu_tree->load('footer', $parameters);
$manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
);
$tree = $menu_tree->transform($footer_tree, $manipulators);
$menu = $menu_tree->build($tree);
return array(
'menu' => $menu,
);
}
[adding a new answer since this is a completely different approach than my earlier one]
If a CSS-based solution is acceptable, this seems to work okay:
.page-node-type-press-release {
a[data-drupal-link-system-path="press-room/press-releases"] {
// active CSS styles here
}
}

Hide Drupal nodes from search

I made a private section on a drupal site by writing a module that checks the RERQUEST_URI for the section as well as user role. The issue I am running into now is how to prevent those nodes/views from appearing in the search.
The content types used in the private section are used in other places in the site.
What's the best way to get Druapl search to ignore the content/not index/not display it in search results?
There is a wonderful article that explains just this on the lullabot site.
It's worth reading the comments to the post too, because people there suggested alternate ways of doing that, also by mean of contrib modules (rather than implementing some hooks in your own code). Code for D6 is in the comment as well.
HTH!
The lullabot article is a bit outdated and contains many blunt approaches. It also contains the answer in the comments - the Search Restrict module which works for DP6 and allows fine-grained and role-based control. Everything else either prevents content from being indexed, which may not be desirable if there are different access levels to content, or affects all search queries equally, which will also not work if there are different access levels.
If the content types used within the Private section are also used elsewhere how are you hoping to filter them out of the search results (note that I've not looked at the lullabot article by mac yet).
Basically, if you look at the details of two nodes, one private and one public, what differentiates them?
Note: I'm assuming that you want the nodes to appear to users with access to the Private area but not to 'anonymous' users.
For Drupal 7.
You can hide the node from search results by using custom field. In my case, I have created a custom field in the name of Archive to the desired content type and with the help of that custom field you can write the my_module_query_alter functionality.
Code
function my_module_query_alter(QueryAlterableInterface $query) {
$is_search = $is_node_search = FALSE;
$node_alias = FALSE;
foreach ( $query->getTables() as $table ) {
if ( $table['table'] == 'search_index' || $table['table'] == 'tracker_user') {
$is_search = TRUE;
}
if ( $table['table'] == 'node' || $table['table'] == 'tracker_user') {
$node_alias = $table['alias'];
$is_node_search = TRUE;
}
}
if ( $is_search && $is_node_search ) {
$nids = [];
// Run entity field query to get nodes that are 'suppressed from public'.
$efq = new EntityFieldQuery();
$efq->entityCondition('entity_type', 'node')
->fieldCondition('field_archive', 'value', 1, '=');
$result = $efq->execute();
if ( isset($result['node']) ) {
$nids = array_keys($result['node']);
}
if ( count($nids) > 0 ) {
$query->condition(sprintf('%s.nid', $node_alias), $nids, 'NOT IN');
}
}
}

Categories