Drupal: Associating grouping more than one CCK field - php

I have an article content type with a node reference CCK field that links to other articles (related articles) .
I need to add a text field for each node reference that allows an admin to specify "why it's related". How do I go about this in D6?
Articles can be related with other articles so it makes sense to have the "why it's related" to go in the main article referencing the related articles.
This is using the text area type ahead so that the user will be given teh drag and drop UI for reordering.
Ideally it would be something like:
*related article 1
*Why it's related.
////
*related article 2
*why it's related 2.
//////
....
The last ditch effort is to not have them associated and then the admin just makes sure that the line up. Not nearly as great of a user experience, but workable I guess.

You can do this with CCK 3.x, using the Multigroup module that comes with it. Note that this doesn't have a stable release at this point, but will work fine for most use cases.

Related

What is the best way to create page in Drupal 8 so that I can then add these posts with images?

I have a Home page on the Drupal website (such as is created after installation), but I still need to create this page:
What is the best way to create a page so that I can then add these posts with images?
I am just starting to learn Drupal and have heard so far about such ways of creating pages:
1) in admin toolbar: Content / Add Content / Article
2) in admin toolbar: Content / Add Content / Basic page
3) in admin toolbar: Structure / Views / Add Views
Which one should I use? Or maybe there is some other option that I don’t know about?
P.S. At the moment I am more interested how to create empty page on which I can then add posts later, and adding posts it is another question.
Welcome to Drupal.
Drupal ships with the default theme which won't look nice but it does its job in the right way. Now if you want to create a better UI/UX obviously you should create a new theme. But before that make sure to read and understand the concepts behind Drupal. Drupal docs are your first friend.
Drupal Documentation
Drupal considers everything as nodes and that's how Drupal got its power. As you mentioned, Articles, Basic Page etc are called content types and they can be used to create a particular type of content.
Now for your purpose create a new content type and add the fields you need. From the image above I can say your content type needs Title, Image, Category and Date. After creating content type you can create as many contents as you want under the content type you just created. Consider each card in your image as content.
Now you can use a Drupal Core Module Views, to perform DataBase Operations without writing single code. Yes, you can select fields, sort, order etc with Views UI and display it in a page or a part of a page (Block).
I would say just try this out in the default Drupal theme and when you understand how this works, you can start creating your own theme for your project.
Theming Drupal
There is a lot of resources available. But you have to make sure what you are asking is whether you actually need. It will take some time, but it worth.
To build layouts for homepages on Drupal 8 you best friend is https://www.drupal.org/docs/8/core/modules/layout-builder
To build the content blocks inside your home page, you should start creating nodes on a node content type to hold your information. For instance: news content type, with a title, a body, a date, and an image.
For every node type, ex. news, work on the preview display, full display, and any other display which makes sense. These displays can be used later in the Layout Builder directly or in Views, referenced below.
If you wish your list to be dynamic, such as the last 10 entries are shown first, then use a view to hold the content sorted and filtered as you need.
In a nutshell.
Create a content type for your article/news.
Modify the displays of the content types to have at least a summary and full view.
Create the content itself to have something to see.
Create the view (block) to filter and sort your content.
Create a page layout (this makes sense for landing pages) which places your new view and any other content you need in any disposition.
This is roughly what I would do. The steps described above contain many intermediate steps. If in doubt, check the docs.
I hope that helps!
First, decide what will you display on that page. Is it content in some existing content type (article maybe) or you want to crate new one for this purpose.
If you need new one then create it (Structure -> Content types -> Add content type).
Then check what fields will you need. I.e. image, some description text. Add missing ones.
Create few nodes (pages) in that type so you could work with them.
Then for displaying you should crate a view (Structure -> Views -> Add view). It can be a page view (you are displaying only that content on page) or block view (this is just a block among some others). If you create a page you could visit it and if you create a block you have to add it to some region to appear on page (Structure -> Block Layout).
Inside your theme you should create templates for this page/block. Turn on twig debug mode so it will show you hints - what templates are used and how can you name yours to override default ones.
Adjust CSS to make it look like you want it to look.
Find some tutorial(s) for the details
Previous answers have given the flow of the work you should go through, I would like to add some resource that might help you achieve this.
Creating content type and fields: https://www.drupal.org/docs/administering-a-drupal-site/managing-content-0/working-with-content-types-and-fields
https://www.drupal.org/docs/user_guide/en/structure-content-type.html
View and View modes: https://www.drupal.org/docs/user_guide/en/views-concept.html
https://www.drupal.org/docs/8/api/entity-api/display-modes-view-modes-and-form-modes
Handling block of the view: https://www.drupal.org/docs/8/core/modules/block/overview
Feel free to ask if any further explanation is needed.
Thank you

Render custom list of related entities as form using SonataAdmin bundle

I am using Sonata Admin bundle in my Symfony app with doctrine. Now I am facing to some specific requirement whose solution or good/best practice I could not find anywhere.
To explain my issue I will use three simple entities as below.
So every news can have title and description different for every language.
Now what I need. In form view (detail) of news I want to:
have inputs of news attributes. (like code or created_date in this case)
then I want to see titles and descriptions for all languages related to current news. And in case, that news has not translation for some language, it means that there is no relation in News_Translation, I want to see empty inputs.
So everything in one view (maybe split it into more tabs). And here is a simple example of news detail (form view) for better understanding
Is it possible to attain something like this? I am open to any other ideas how to solve it using sonata-admin.
KunstmaanTranslatorBundle is a bundle which enables editing translations in the admin interface without need for editing the translations files. Translations will be stored in a (default) database and retrieved on the most efficient way possible.
KunstmaanTranslatorBundle
Doc

Drupal custom field customization

I am using Drupal 7.
I created a custom field for article nodes, which is a text field, with unlimited values so it's essentially an unordered list. I want to be able to customize the area in which the new field is displayed, but no page.tpl.php it renders under the page content, with the body. The new field does not create a new block in which I can edit. I want to limit the containing div to 350px, and then place a 300x250px ad to the right. So the custom field list on the left, with an ad on the right. If anyone knows a way to doing this rather than finding the div ids and sloppily overriding the CSS to do this please let me know.
I'm not sure your use case and requirements are completely clear to me, but it sounds like you might want to read up on "Render arrays", a new-in-Drupal 7 feature which allows more fine-grained control of content output/display. This is part of the Drupal Core and the official documentation might be a good starting point, but there are many other articles and tutorials (use: "render array" Drupal <-- your search on Google) which might be helpful.

Adding interactions to admin pages generated by the admin generator

I am using Symfony 1.2.9 (with Propel ORM) to create a website. I have started using the admin generator to implement the admin functionality.
I have come accross a slight 'problem' however. My models are related (e.g. one table may have several 1:N relations and N:N relations). I have not found a way to address this satisfactorily yet. As a tactical solution (for list views), I have decided to simply show the parent object, and then add interactions to show the related objects.
I'll use a Blog model to illustrate this.
Here are the relationships for a blog model:
N:M relationship with Blogroll (models a blog roll)
1:N relationship with Blogpost (models a post submitted to a blog)
I had originally intended on displaying the (paged) blogpost list for a blog,, when it was selected, using AJAX, but I am struggling enough with the admin generator as it is, so I have shelved that idea - unless someone is kind enough to shed some light on how to do this.
Instead, what I am now doing (as a tactical/interim soln), is I have added interactions to the list view which allow a user to:
View a list of the blog roll for the
blog on that row
View a list of the posts for the blog on that row
Add a post for the blog on tha row
In all of the above, I have written actions that will basically forward the request to the approriate action (admin generated). However, I need to pass some parameters (like the blog id etc), so that the correct blog roll or blog post list etc is returned.
I am sure there is a better way of doing what I want to do, but in case there isn't here are my questions:
How may I obtain the object that relates to a specific row (of the
clicked link) in the list view (e.g. the blog object in this example)
Once I have the object, I may choose to extract various fields: id etc.
How can I pass these arguments to the admin generated action ?
Regarding the second question, my guess is that this may be the way to do it (I may be wrong)
public function executeMyAddedBlogRollInteractionLink(sfWebRequest $request)
{
// get the object *somehow* (I'm guessing this may work)
$object = $this->getRoute()->getObject();
// retrieve the required parameters from the object, and build a query string
$query_str=$object->getId();
//forward the request to the generated code (action to display blogroll list in this case)
$this->forward('backendmodulename',"getblogrolllistaction?params=$query_string");
}
This feels like a bit of a hack, but I'm not sure how else to go about it. I'm also not to keen on sending params (which may include user_id etc via a GET, even a POST is not that much safer, since it is fairly sraightforward to see what requests a browser is making). if there is a better way than what I suggest above to implement this kind of administration that is required for objects with 1 or more M:N relationships, I will be very glad to hear the "recommended" way of going about it.
I remember reading about marking certain actions as internal. i.e. callable from only within the app. I wonder if that would be useful in this instance?
I'm assuming your application is called backend. Suppose there are two models, BlogPost and BlogPostComment. These are managed using admin generated modules called blog_post and blog_post_comment.
I believe you want a link against each BlogPost displayed on the list page at backend.php/blog_post. The links take you to backend.php/blog_post_comment, which should only show comments related to the relevant BlogPost.
Under apps/backend/blog_post/templates, create a file called _commentslink.php and put this in it:
View Comments
Then in apps/backend/blog_post/config/generator.yml, you need to include this partial in the fields for the list view:
....
param:
config:
list:
display: [ id, title, _commentslink ]
Note the _commentslink - the _ tells it to use a partial instead of looking for the field in the model. Your object is available in this partial as $<name of model> - $blog_post in this case.
Essentially, all this method does is links to the same action as the filter on the comments list normally goes to, passing the relevant condition to it to make it filter by blogpost_id.
If you've got CSRF protection enabled in the backend, you'll need to disable it, or this method won't work. This is set in apps/backend/config/settings.yml. There will be a setting in there called csrf_secret - it should be set to false to disable csrf.
You should try symfony 1.3/1.4 out if you need support for 1:N relationships in forms. 1.3 is in my experience a relatively hassle free upgrade from 1.2.x - 1.4 is the same, but with deprecated features removed.

Drupal linking a Username to a Node

In Drupal I wish to create a content type as a bio for a user. When you click on a a user name on the site it takes you to there bio. An example I have found online is below.
This article has the authors name Jeff Robbins. Jeff Robbins name links to his profile. How would you go about doing something similar? It does not seem be using the default profile module.
I would ideally only like this to happen for users in a certain group. For other users I wish just for there name to display but no link. Any pointers about how I would do this?
You've already got the core/programming route explained, so I thought I'd chime in with a few signposts on the install-a-module route. As always, with modules there is a bloated but supported solution and guidance on DIY.
Content Profile
Content Profile is a module specifically targeted at supported a User Biography as a node.
Here is an article describing how to add author biographies to nodes using Content Profile.
Author Pane
This module pulls information from the profile with an eye toward creating the sort of author information you would find to the left of a messageboard post.
Permissions
There are a couple modules that add finer control to the Profile permissions mechanism. There may be more, but these jumped out while I was looking for Content Profile.
Profile Role
Profile Permission
The node creator is stored in the node table (column UID), you could write something in a nodeapi hook to take that insert it as a field which can then be themed however you want. You could even in this hook put some logic to make the name a link or not depending on the roll.
You may want to look at the profile module, as this will allow you to set up a bio much more easily.
You can like Jeremy suggests do something like using hook_nodeapi(), but that seems like a bit overkill. I would instead use the template_preprocess_node() function. You could put this into a module or a theme. With it you can change the variable for $submitted, which holds the info for the author, date published etc. You can format it like you want, and keep the date and all that, and just instead make a different link on the user.
You could make it point anywhere really, so that the user is directed to a custom page that holds info on that user. It could a node on itself that you can setup with CCK ect, or you can use one of the profile modules that let your users customize their profiles, whatever works best for you.

Categories