TYPO3-Upgrade 4.5 to 6.2: namespaces - namespaces

I'm updating an old TYPO3 to latest verison 6.2.12. As I do so I replace deprecated classes with the proper namespaces. E.g. t3lib_div to \TYPO3\CMS\Core\Utility\GeneralUtility or t3lib_extmgm to \TYPO3\CMS\Core\Utility\ExtensionManagementUtility.
But I cant find the proper namespaced class for t3lib_svbase. Any suggestions?
.
And I absolutely have no clue what I need to do with the new xclassed include.
//old XCLASS
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/foo_myfancyextension/sv1/class.tx_foomyfancyextension_sv1.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/foo_myfancyextension/sv1/class.tx_foomyfancyextension_sv1.php']);
}
It should look something like this:
//new XCLASS
$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']['TYPO3\\CMS\\Frontend\\ContentObject\\FluidTemplateContentObject'] = array(
'className' => 'Enet\\FxLibrary\\Xclass\\FluidTemplateContentObject',
);
But where is the path to my extension and the class itself?

As can be found in typo3\sysext\core\Migrations\Code\LegacyClassesForIde.php t3lib_svbase has become \TYPO3\CMS\Core\Service\AbstractService.
You can't directly instantiate this class, since it is abstract, but you can work with any of it's children.
As for this block:
//old XCLASS
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/foo_myfancyextension/sv1/class.tx_foomyfancyextension_sv1.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/foo_myfancyextension/sv1/class.tx_foomyfancyextension_sv1.php']);
}
I assume, that this is part, which is found at the bottom of your files. You can safely remove it, since as #pgampe suggested, there is new way of XCLASSing, which no longer requires these lines.

To use the new XLASS feature, you need to provide a proper autoloading, by either sticking to the convention or by creating an ext_autoload.php file.
http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Autoloading/Index.html
http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Xclasses/Index.html

Related

How to know which rules were applied during autoformatting using PhpStorm?

I am trying to figure what rules PhpStorm is using in my current file during autoformatting via "Reformat Code" so I can tweak it better. Is there way to view the rules that were applied?
A more concrete example:
I have a file with this code:
public function rules(): array {
return array_merge(parent::rules(), [
['foo', 'bar'],
];
}
that is converted into:
public function rules(): array {
return array_merge(parent::rules(),
[
['foo', 'bar'],
]
]
}
but I don't know which rule I have to tweak in order to not apply that change. I also want to be able to tell in other cases which ruleset caused which change during autoformat.
Is that possible and if so how?
In general, you can check that by selecting a code block and then Help | Find Action | Adjust code style settings.
But, please be aware that it is not all that precise, it can and does miss things. In your particular case, try playing around with Function/constructor call arguments and Array initializer in Wrapping and Braces.

How to mark a CSS class as deprecated

is there a (good) way to mark a CSS class as deprecated?
The idea is during refactoring, when you create new clean classes, but want to update your site gradually so you have to keep both the old and new class for some time, but you would like other to only use the new class for new features.
A comment in the class definition is a first step, but only helps when you actually check the class implementation, it doesn't help when the class usage is just copied from somewhere else.
What I'm looking for is rather something that would be displayed in the IDE or where a linter could throw a warning
You can put messages inside your css rulesets like so:
.center {
text-align: "center";
--deprecated: "WARNING: Use .other-class instead";
}
This way developers and users can see the message directly in their browsers and take action
You can simply add comment to the old class (for example: /* duplicate, new class created*/, so that you know what to delete after you have new class.

Templatizer - How to render multiple times same template, Polymer 2.x

In Polymer 1.x I was used to write a templatize code like this:
renderTemplate(query, properties) {
let element = this.shadowRoot.querySelector(query);
this.templatize(element);
var instance = this.stamp(properties);
return instance;
}
which worked well. But in Polymer 2.x there is a new error message A <template> can only be templatized once. Well it doesn't make sense, because I have 1 template which I want to redistribute multiple times with different properties.
I am giving here an example of how is my code
I have #template1 and #template2
I want to render #template1 then #template2 then #template1.
In steps how I render templates:
1) templatize #template1
2) stamp properties
3) templatize #template2
4) stamp properties
5 a) templatize #template1 => ERROR
5 b) skip templatize and stamp properties => #template2 is rendered....
How am i able to make this possible? calling stamp() after rendering #template2 will result in another #template2 render. I want #template1, but I can't templatize #template1 because it has been already templatized. And stamp is always "binded" to last templatized element.
Am I doing something wrong? I do really hate Polymer because of it's bad documentation and hard to google something usefull
I found a workaround which is propably not the best solution but it works. I tried to search in source code for some solutions but there wasn't anything usefull except the one property called __templatizeOwner. This property is set to all templatized elements. Removing this property from an element is the way.
renderTemplate(query, properties) {
let element = this.shadowRoot.querySelector(query);
if(element.__templatizeOwner) {
element.__templatizeOwner = null;
}
this.templatize(element);
var instance = this.stamp(properties);
return instance;
}
I am not sure what side effects this might have (more memory usage or something) but this is the only way I was able to find out.

How to check if a class mixin has been applied to a Polymer element?

I would like to check if a mixin has been applied to a custom element, but I don't think I can use 'instanceof', since a mixin is not properly a base class (I tried, of course).
I would need to enforce that an element added to a collection can be only of a kind with a particular class mixin applied...
Any suggestions?
Not sure I understand you question correctly.
I assume you want to check something like MyCustomElement has already apply MyMixin or not?
You can check from the instance
let instance = new MyCustomElement()
console.log(instance instanceof MyMixin)
This will only work when MyMixin is a class not a factory function. If you follow documentation you need to change it.
Another way, you can declare some static function in MyMixin. Then you can call from MyCustomElement to check it.

Render different partial templates in EpiServer

I have a page partial that is supposed to render inside a ContentArea when the page is added there. This works perfectly, but now I have two different ContentAreas on two different pages and I want the same child page added to those to render different on each parent page.
I get that I could in some way use a Tag when rendering the partial to differentiate between the ContentAreas:
#Html.PropertyFor(m => m.MyBlockProperty, new { Tag = RenderingTags.Sidebar })
#Html.PropertyFor(m => m.MyContentArea, new { Tag = RenderingTags.Sidebar })
But then, in my SomePage.cshtml (which is my partial view), do I get a varaible or something here so I know which Tag was asked for? Or is there some naming convention like SidebarSomePage.cshtml so that I can define multiple partial templates? Do I have to create a controller to deal with this? It seems unneccessary to me, I just want to change the html a bit depending on page...
Create a PartialContentController<T> and then use the TemplateDescriptorAttribute to specify the tags you wan't to use. Then use PropertyFor as Johan explained in the view.
From the EPiServer documentation
The template you choose to render a content instance depends on the specific context such as channel and tagging. For a template to be automatically registered it has to implement EPiServer.Web.IRenderTemplate (where T states which model it can render). If you use a base class for your template like PageBase, ContentControlBase, BlockControlBase, PageController, PartialContentController or BlockController, then you do not need to explicitly implement the interface because that is done by the base class. In addition, you can use the TemplateDescriptorAttribute to specify more details about the template such as tags and inheritance, more information on that topic later.
I'm pretty sure you can access the tag from the ViewData dictionary in your view (or controller) like this:
#ViewData["Tag"]
You can also pass any other setting to the view
#Html.PropertyFor(m => m.MyContentArea, new { Tag = RenderingTags.Sidebar, RenderThisPartialDifferently = true, ShowHeading = false })
And then access them:
#ViewData["RenderThisPartialDifferently"]
#ViewData["ShowHeading "]
And then you have the option to have a controller in between and render a completely different view.
Pretty sure there is a naming convention for tag views as well. What I do know for sure though, is that you can put a view with the same name as the tag in /shared/displaytemplates. But that's not what you're asking for now.
Also addition to all answers, you can use template registrator to register additional templates for specific tags.
[ServiceConfiguration(typeof(IViewTemplateModelRegistrator))]
public class TemplateCoordinator : IViewTemplateModelRegistrator
{
public void Register(TemplateModelCollection viewTemplateModelRegistrator)
{
viewTemplateModelRegistrator.Add(typeof(MyBlock), new TemplateModel
{
Tags = new[] { RenderingTags.Sidebar },
AvailableWithoutTag = false,
Path = BlockPath("Some-Other-Template.cshtml")
});
}
}
This will make sure that if block is rendered "inside" RenderingTags.Sidebar context (for instance via Html.PropertyFor(...., new { tag = RenderingTags.Sidebar })) file Some-Other-Template.cshtml will be used.
AlloyTech has sample code there.