Override view (from other package), fix browser layers priority - plone

I have a other.package registering a view my_view. Then I'm trying to replace this view with a view defined in mine this.package.
<browser:page
for="other.package.interfaces.IBarClass"
name="my_view"
class="this.package.views.FooClass"
permission="zope2.View"
layer="this.package.interfaces.IThisPackageContentLayer"
/>
For some reason my_view is not overrided. I think its about layers priority maybe, but I have no idea how to fix it. Any suggestion?
If I rename the view (name="my_view_new") it is working as expected. But if the same name is used, the original one seems to have priority. How can I change this?
UPDATE:
It's about layer priority:
(Pdb) self.request.__provides__.__iro__[13]
<InterfaceClass other.package.interfaces.layer.IOriginalLayer>
(Pdb) self.request.__provides__.__iro__[14]
<InterfaceClass this.package.content.interfaces.IThisPackageContentLayer>
You can check the activated layers from HTTP request object by looking
at self.request.provides.iro. Layers are evaluated from zero
index (highest priority) the last index (lowest priority). (source)
So, the problem is how can I prioritize a layer?

The problem was fixed by fixing the layers' priority this way:
class IThisPackageContentLayer(IOriginalLayer):
as suggested here.

Another way is, to use ZCML-Overrides with the same browser layer.
That should also override the original, but the solution with sub classing the original layer is a bit nice ;).

Related

Is there any way to add multiple "Auto Number Prefix" in oracle ucm?

See, I have a requirement in which I am supposed to change the "Auto Number Prefix" for only one profile, I am wondering if there is any way to achieve that?
You should be able to set AutoNumberPrefix in a rule side effect and have it apply only to that rule/profile.
<$AutoNumberPrefix="profile1_"$>
For those who wants the answer for this, I found the method to provide the different prefix for different profile type. Go in Admin Server-> Configuration -> Paste this code;
AutoNumberPrefix=<$if dDocType like 'Profile_name'$>Prefix Name<$else$>another prefix name<$endif$>
Adding the code shown as "correct" is actually the more inflexible way to do this. Any changes require a restart of the Content Server.
Jonathan's answer was really close, but the syntax used ensures that the variable "AutoNumberPrefix" remains in the profile context. It needs to be placed into local data to be used. This is accomplished using the function "dpPromote".
<$dpPromote("AutoNumberPrefix","profile1_")$>

Filter at event viewer by data

I want to get event entries by their description (data).
I know how to get the event entry with a certain description, however I want to get an entry whith a description which contains a string (not equals to it).
That, I don't know how to do.
Please help :)
According to my answer here: https://stackoverflow.com/a/34119006/5089204 you should be able to retrieve EventRecords.
Dealing with these events is a quite complex issue... Each event has its own internal structure. The common properties are bundled in EventRecord, but the specific data must be taken from the internal details. Use the ToXml() method of an EventRecord...
In order to get the right events you must define an EventLogQuery. You must know the Provider's name and specify the filter.
Try the following: Open eventvwr and there the Windows-System queue. Right click one event, open the "Details" and choose the "XML-View". Look over different events and you will find, that they are quite differing.
But: You'll find everything you need there: First the "Provider Name" and the "EventId", these two are most important for the `EventLogQuery'.
Now go to the "define a user filter on the current protocoll"-action and type in some values. Then switch to the filter's XML and you'll learn how to define the correct query.
I'm sorry, there is no "easy and general" approach :-)

Less override variable just for one country (language)

The context of my problem :
I have a website multi-language ( 20 ), I use less css.
All stylesheets are common, except one for every country called to the end.
I have a file com.base.less which has a variable of font.
Every stylesheet calls this file to use the variables which it contains.
My question, for a country I must change the font, thus to re-declare the variable only for this country.
How can I proceed?
Because if I re-celare my variable in my file of country, that this being called to the end it isn't written again.
I use lessPhp, and I see ModifyVars but I don't know if it's good method ?
(when I test he doesn't work)
Thank you
Yes, as the docs tell you "You can use the ModifyVars() method to customize your CSS if you have variables stored in PHP associative arrays".
Less uses the last declaration wins rule for variables, so the last re-declare value of variable at the end of your code will be used everywhere in your code.
I use lessPhp, and I see ModifyVars but I don't know if it's good
method ? (when I test he doesn't work)
Make sure that you call ModifyVars() before getCss() and call both on the same instance of Less_Parser.

Plone Conditional - If Content Type is Versionable

Is there a simple way to check if a content-type, or a specific object, has Versioning enabled/disabled in Plone (4.3.2)?
For context, I am making some unique conditionals around portal_actions. So instead of checking path('object/##iterate_control').checkout_allowed(), I need to first see if versioning is even enabled. Otherwise, the action in question does not display for items that have versioning disabled, because obviously it isn't checkout_allowed.
I didn't have any luck with good ole Google, and couldn't find this question anywhere here, so I hope it's not a dupe. Thanks!
I was able to get this working by creating a new script, importing getToolByName, and checking current content type against portal_repository.getVersionableContentTypes(). Then just included that script in the conditional.
I was looking for something like this that already existed, so if anyone knows of one let me know. Otherwise, I've got my own now. Thanks again!
The first thing that checkout_allowed does is check if the object in question supports versioning at all:
if not interfaces.IIterateAware.providedBy(context):
return False
(the interface being plone.app.iterate.interfaces.IIterateAware:
class IIterateAware( Interface ):
"""An object that can be used for check-in/check-out operations.
"""
The semantics Interface.providedBy(instance) are a bit unfortunate for usage in conditions or TAL scripts, because you'd need to import the interface, but there's a reversal helper:
context.portal_interface.objectImplements(context,
'plone.app.iterate.interfaces.IIterateAware')

Drupal 7 function menu_tree_page_data not working correctly?

Reading the documentation for menu_tree_page_data(), it seems to me that I should be able to retrieve the entire contents of my main menu by calling the function in the following way: menu_tree_page_data('main-menu'). Since param 2, $max_depth, defaults to NULL, this should recursively go through all levels. Since param 3, $only_active_trail, defaults to FALSE, this should retrieve all links, not just those on the active trail.
However, when calling this function, I end up with the following type of tree data.
All links on the first level of depth.
All links on the second level of depth.
Only active links on the third level of depth.
What's going on here? I've also tried explicitly setting params as menu_tree_page_data('main-menu', 10, FALSE) just to make sure that I was not misinterpreting the default behavior. I've had to write my own function to give me the entire menu, but it doesn't have active-trail data. Now, I'm finding myself in a situation where I'm blending the two functions to create a full menu tree WITH active-trail information, and it is extremely messy. It'd be great if one solution just worked.
Alternatively, is there a simple way of determining active trail for a given menu item? If so, I'll just add that to my already-working tree-crawler function and call it a day.
I think it's a problem with the static caching in menu_tree_page_data(). The cache ID is built up using (among other things) the $max_depth passed into the function or MENU_MAX_DEPTH, whichever is smaller.
Since MENU_MAX_DEPTH is equal to 9, when you pass 10 into the function this is automatically reset to 9, and the cache ID is built from that. If another function has already called menu_tree_page_data() with MENU_MAX_DEPTH as the $max_depth argument (which does happen earlier on in a Drupal page), and with $only_active_trail set to TRUE then the statically cached data will be returned with only active trail items.
I think the following will work:
drupal_static_reset('menu_tree_page_data');
$tree = menu_tree_page_data('main-menu');
If it doesn't, you might also need to clear the cache for another function that's involved (_menu_build_tree()) so try this:
drupal_static_reset('_menu_build_tree');
drupal_static_reset('menu_tree_page_data');
$tree = menu_tree_page_data('main-menu');
Hope that makes sense it's quite tricky to explain :)

Resources