I have an entity which have a slug field defined and managed using Gedmo Slug library.
Is it possible to easily define a list of unwanted values for this field (e.G. 'edit', 'new', 'delete'...) or do I need to make something all by myself?
You could use a SlugHandler I guess.
Take a look at this : http://atlantic18.github.io/DoctrineExtensions/doc/sluggable.html#slug-handlers
You could create your own SlugHandler, add some SlugHandlerOption with your forbidden words, and use a simple regex to check if the generated slug is valid.
If not, you could modify the generated slug or throw an exception.
I hope to understand your request. It lacks a bit of clarity.
In my opinion, the Gedmo librairy can not do this easily.
In your place, I will create a value that I will work according to your imperatives and I will let the annotation slug work with this value.
Related
Why I need this?
When I want to change the route from /news/{slug} to /news/{id} for example, I need to replace all places where path('news', {'slug': 'my-post'} is called. I want to pass the entity like so path('news', {'post': post}) and then change the route however I like. This will give me the flexibility to easily change the routes. Thanks.
You cannot pass eneity as param. path function takes only string and number arguments, because this function generate url based on routing.
How do you imagine passing object to browser url bar?
/news/"{object": std_what_the_#?}
Of course you can make your own twig function and pass object to make your url.
This way you can check your object has slug property and choose your route and params. Anyway you have to do it myself.
I hope it help but your question is not clear...
I currently am trying to make a variable using the current url for the view. To get the url, I am using {% set uri = app.request.uri %} (uri being my variable which is the current url for that particular view). The thing is, I am only interested in what makes the url unique (the end of it - a unique object from an array - happens to be a uri), and not the beginning (path to my application). I was thinking I could use a preg_replace to do so, but TWIG doesn't have this function. Just wondering if someone would know how to accomplish what I am trying to do?
I'm new to Symfony (and fairly new to PHP), so my explanations may not be clear (sorry).
Ex.
{% set uri = app.request.uri %}
output: http://website.com/http://item.org/1
I want to modify the uri variable to ONLY have http://item.org/1 (and not the path to my website).
I'm thinking creating a Twig Extension with the preg_replace will allow me to do this ..but not sure if it's the best way to go (inexperienced).
Overall goal:
The unique value for "uri" in the view is appended to the websites path by another view from an array of objects ($results) with attributes, one being "uri". My ultimate goal is to only display all associated attributes (or row) for an object in my $results array. I was thinking I could do this by first creating a key (my uri variable) in a foreach, and returning the row in the array which matches this key. This is why I am trying to create a variable with the url so that I can use it as a key for my foreach loop to iterate over $results. I am NOT using a database or Doctrine.
Thank you ahead of time for the help!
The best way is to move the logic from template to the controller.
If you need preg_replace in twig you must create custom extension.
Someone seems to have created a Twig Extension for preg_replace, see https://github.com/victor-in/Craft-TwigPCRE
You can do it like that. It's a bit ugly but it works.
uri|split('base_path')|join('')
In Archetypes, in order to move a field from a fieldset (or schemata) to another, we can do the following:
schema['creators'].schemata = 'default'
However, I'm not achieving the same using Dexterity. I've tried using form hints. Ex:
form.fieldset('default',
fields=['creators']
)
I notice that it doesn't work because the field "creators" is unknown at this time. (The ownership behavior wasn't evaluated yet).
Nevertheless, with form hints, I can move from "default" to another (eg. "ownership").
myfile = NamedFile(title=_(u"A file"))
form.fieldset('ownership', fields=['myfile'])
How can I do that? Writing my own behavior?
Thx!
You likely need to make the define the field you want to assign on an interface under your control. While this seems duplicative, it is a good idea for purposes of being complete and explicit. You can either:
(1) Declare 'creators' field on your content type interface (likely, recommended solution), or...
(2) Use your own behavior as documented here (and adding this behavior to the type's FTI in portal_types and associated setup XML): http://docs.plone.org/external/plone.app.dexterity/docs/behaviors/creating-and-registering-behaviors.html
The first solution should be the easiest. Any fields that you wish to control fieldset location or order of should likely be defined by your interfaces anyway.
I want to add extra field in story content type using hook, I don't want to use CCK, because am trying something different.
Please tell some suggestion with hook method.
If you do not use CCK, you will have to create your database table and code to add the form field, validate the form field, capture the data and save it in your field. I know cck can be a monster, but it does all this for you. I'd be happy to give you more info on all of this, but it is quite lengthy
There are lots of reasons that you may want to do this without CCK or Fields, and the best example is found at the node_example module in the examples project which can be found at: http://drupalcode.org/project/examples.git/tree/refs/heads/6.x-1.x:/node_example. You can also view the documentation on api.drupal.org.
The short version is that you're going to have to define your own node type using hook_node_info() and then define all the hooks for _load(), _insert(), _update(), _delete(), _access(), _validate(), and _view() in addition to defining your schema in your hook_schema and managing your tables on your own.
Sadly there is no good example for Drupal 7 as the node_example module for 7 was converted to use fields instead of the hooks listed above, which are still fully documented on api.drupal.org (they do now typically act on an array of nodes instead of a single node, but are otherwise identical).
I'm currently using Drupal Views 2 to build custom views. This works fine so far, if there wasn't a feature needed: One should be able to filter the results by different fields via URL, in the form of:
http://domain/node/M/[key]:[value],[key2]:[value2],...,[keyN]:[valueN]
The key names are fixed and may not be altered.
I tried hooking hook_views_query_alter() and hook_views_pre_render() to generalize this for all views, evaluating the given filterset, but to no satisfying end, as i could not get hold of the query used to build the view (I could not alter it in the proper way, as i do not know the field names in the query).
The question is, if there is a nicer way to implement such a filterset.
thanks in advance,
flo
Looking at the comments you seem to want not only url arguments but url arguments in a custom format.
I would firstly urge you to drop your format and use the standard views argument format, this will be more standards compliant and save you a lot of headache.
If you want to use that paticular format you are going to have to write some custom code in a module.
Register a callback using hook_menu().
In that callback use arg() and decode your arguments.
Pass the arguments to views_embed_view(). as shown here