Symfony2 - Generate input fields based on entity - arrays

I'm having a trouble with creating a dynamic form in Symfony2.
What i wanna do is to register a collection of text field which are generated from an entity.
I dont know where to start exactly but here's a kinda of pseudo-code of what im trying to do :
in my view :
{# list_type_url are retrieved from DB #}
{% for url in list_type_url %}
<input type="text" name="link[{{ url.name }}]">
{% endfor %}
I started in my form builder with this :
$builder->add('link', CollectionType::class)
but I dont know how to link the array in the view with the form.
Maybe Im thinking it wrong ?
EDIT:
I edit the post to make things clearer :
the list_type_url variable is coming from an another entity. Let's says it is named UrlType, in which I can create a type of url.
Then in an another entity, imagine "Contact", i want to be able to add all the type of existing url.
so concretely, I could create 3 types of url or more (lets say top, middle, bottom) and in my contact form, i have to display those 3 types and fill them with different urls and i should be able to retrieve each of the types for a particular contact.
I've also readed how to dynamically modify forms but I really don't see how to use it with my problem
I hope i get more clearier

Related

Drupal 7: How do I extract specific field in a taxonomy page

How do I extract specific field for display in a taxonomy page?
I have a custom content type called "film" and each film has a Term Reference field called "casting". As expected I can click on a "casting" (tag) it brings me a page where all films are listed wherever this tag is associated. For expample if I click on "Kate Winslet" from movie Titanic, I land on a page http://localhost/mysite/tags/kate-winslet where other movies of Kate Winslet are listed. Up to this point everything is just fine.
I do not want Drupal to pull in and show default fields like just Title and Body in its own display format. Rather I want it so that I can display a photo from each film, year of release and of course the title and trimmed version of the body. I only want to customize the content of this page so that I have the control over What to Show and Where To Show a specific field value.
This is what I tried:
I cloned and put page.tpl.php in my theme's template folder. Renamed it as page--vocabulary--tags.tpl.php. Then I took out the following line of code (<?php print render($page['content']);?>) from my page--vocabulary--tags.tpl.php. The intention was to check whether the overridden template is actually being accessed by Drupal or not. It does!
But I am not been able to extract fields like field_photo or field_release_date from $page['content]. To get an idea about defined variables and how they are placed I used the following line of code:
<pre><?php /*print var_export(get_defined_vars(), TRUE);*/ ?></pre>. But even from there I could not extract a particular field like I mentioned above. The fields look to be somewhere inside $page['content']['system_main']['nodes'], but I don't know how to get to a specific field directly.
I also created a template.php with the following preprocess hook function:
<?php
function introduction_preprocess_page(&$vars) {
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
$term = taxonomy_term_load(arg(2));
$vars['theme_hook_suggestions'][] = 'page__vocabulary__' . $term->vocabulary_machine_name;
$vars['content'] = $vars['page']['content']['system_main']['nodes'];
}
}
?>
Both <?php print render($content) ?> and <?php print render($page['content']) ?> print the same result but I want something like <?php render($content['photo_field'])?> which I am not been able to.
I am sorry for making this too long. I have just stepped into Drupal. So wanted to make sure that what I am trying to explain matches exactly what I want to accomplish.
You are probably trying the long way to this.
You can use Views module. It allows to create custom listings querying the database, but also override existent ones, like the case of the taxonomy term page listing.
Once you have the module installed (if it's not yet), particularly the Views UI module, go to /admin/structure/views and scroll to bottom, where disabled views (grayed rows) are. You'll find one called Taxonomy term, described as 'A view to emulate Drupal core's handling of taxonomy/term.'
Click Enable on the right of it and then go to the same place where the Enable link is, click the arrow to unfold and choose Edit.
Once you're in the view edit page, you can manipulate the listing at your convenience, adding/removing fields or whatever you want to do in your particular case. If you are not familiar with Views, I recommend you to learn about it, there is a lot of related content on the web and it is close to essential for Drupal development.
Also, if you want to add more customisation to the page, you can use the same approach with the Panels module, who allows to override system pages (not just listings like Views).

Twig create array and place them in specific places

I'm pretty new to Twig and can't figure one thing out!
I'm trying to create a homepage where in different spots images need to be placed. I know this can be done by executing a function where an image need to be placed. Problem is that I have to do that 7 times on one page.
So my question is if you can create some sort of array and then get the results from the array in the appropiate spots.
See below
Let's say I want to place an image in A,D,E,G. What would be the quickest way to accomplish that? What I already can do is
{% for product in products %}
{% endfor %}

Drupal 7: Adding content/nodes from custom content type pages to another page

I'm working on a Drupal site an need to implement the following:
I have created an about us page template (page--about.tpl.php) and a custom content type for the about us page and linked the 2 using suggestions. I also have a custom content type for staff profiles that I need to add on the about us page in a tabbed format.
I can't seem to find a way to get the staff content to display in the about us page. I would ideally like it to render it the same manner as blog posts would display in a blog page.
So my question is, what code do I use to render all the nodes of the staff profiles content type in the about template page?
p.s I'm a bit of a Drupal noob, done a lot of reading but come up empty on this one.
If you already created content type About us (that is what i understood from mockup and explanation) then maybe you could use Views with EVA. That will enable you to have view as field in content type.
You can set it up with manage display or print it in template as all other fields. For example:
<?php print render($content['your_view_entity_view_1']); ?>
Other way would be to embed view in template. For example:
<?php print views_embed_view('your_view', 'block'); ?>
You can use the excellent Views module to create a block to list all your staffs.
Then you need to place the block that you had created with the help of view module in about-us page.
The Views module will give you suggestions to about which template to use.
EDIT: After the op provided the following image.
After you create a view to show all the Team member nodes you could simply print the view in your about us specific page template using following code.
$view = views_get_view('view name');
print $view->render('display_id');
Another option to do the same thing is, make blocks for all the content, viz. The Firm, The Team, Awards, Technonogly, Services and use quicktabs to display the content.
Yet another option to show a view as a field for a node is use EVA
Going the quicktabs way you can provide a lot of flexibility of showing teaser in about us page and leading to details about the same. For example each award can be a node in itself.

Custom editor for tags in Backbone

I'm using backbone forms and have been creating customising editors to meet my needs.
I've now moved onto wanting to edit tags for a model and before I go ahead and implement my own, I was wondering if there was already a custom editor capable of this?
For example, the model could have a tags field stored as a string:
#model.tags # = 'this, and, that, foo, bar')
I want to define my backbone form as follows:
class CPP.Models.Event extends Backbone.Model
# Definitions (url etc)
...
# Form Schema
schema:
tags:
type: "TagEditor"
url: "/someurl"
This would then result in an editor with the following fields:
Text Field - For adding tags, autocompleted with values loaded from url (sending through existing tags so as to avoid duplicates)
Tags Container - Contains all the tags in their own divs (I would then style these)
When I add a new tag by pressing enter it would add the tag to the tag container and then when I later read from the editor, it would condense the tag container/tags back into a comma separated list.
Hopefully this makes sense, I'm almost sure I've seen someone doing this in a github repo somewhere but I've been searching for a good hour through google and my history and I can't find it anywhere.
Help much appreciated!
I eventually found the file on github I was looking for at https://github.com/jumski/backbone-widgets/blob/master/src/views/tag_editor.js.coffee

Salesforce.com visualforce between 2 objects

In salesforce I need to create a visualforce page that includes the fields of 2 objects. The first object is the QUOTE object. The second objects is a custom object with several fields.
I want to create a visualforce page that shows the records of both QUOTE and the new object. Can I do this without creating a custom controller? If no any hints on the code for this new controller?
Can I do calculations between fields in a visualforce page?
Ideally I want this page to appear as soon as the QUOTE is set to ACCEPTED
1: You can't do this without a custom controller unfortunately, unless one object is related to the other and you're just happy displaying it as a related list on the parent object's page. For calculations you could use rollup summaries for some basic sums etc..
As for a custom controller, have a look at field sets for a super easy way to get fields into a VF page, you essentially configure groups of fields on your objects and then you can stick those groups onto a page with minimal markup.
2: For fields with complex calculations you'll want to do the sums in the controller and then expose the results through variables onto the page in the usual manner.
3: Not really possible without creating a custom edit page in the first place — you'd be better off having a button on the quote page to open up the Visualforce page, that page can simply display an error if the quote is not yet accepted. There are some other alternatives that might work though, like using a forumla field to generate a link to the page when the status is as you desire.
I'm happy to elaborate on any of this, but the fact that you're asking about number 2 would suggest to me that you don't have much experience developing on the platform (not a dig, just an observation), so unless you're comfortable coding in other environments you could find this quite tricky. That said, you're on stackoverflow so I'm thinking you probably know a little about coding at least!

Resources