Drupal 7 access field collection data in views - drupal-7

I have a field collection called field_logo_logos.
There are 2 fields within:
field_logo_image and field_logo_link
In views I can get the data and it comes out like this:
<div typeof="" about="/field-collection/field-logo-logos/24" class="entity entity-field-collection-item field-collection-item-field-logo-logos clearfix">
<div class="content">
<div class="field field-name-field-logo-image field-type-image field-label-hidden view-mode-full">
<div class="field-items">
<figure class="clearfix field-item even"><img width="222" height="57" title="title" alt="alttag" src="http://link/to/my/image.png?itok=1wgQypF6" class="image-style-footer-logo" typeof="foaf:Image"></figure>
</div>
</div>
<div class="field field-name-field-logo-link field-type-link-field field-label-hidden view-mode-full">
<div class="field-items">
<div class="field-item even">http://www.mylink.com/</div>
</div>
</div>
</div>
</div>
but how do I override this so I can change it to be like this:
<div class="footer-logo">
<a href="http://www.mylink.com/" target="_blank">
<img width="222" height="57" title="title" alt="alttag" src="http://link/to/my/image.png?itok=1wgQypF6" class="image-style-footer-logo" typeof="foaf:Image">
</a>
</div>
I know how to do this with ordinary fields with tokens within views or in a template override but field collections seem to work differently.
Any advise will be very much appreciated.
C

You can't do this with the current iteration of field collections.
Here's a post, they say they will allow better templating in version 2.x
https://drupal.org/node/1157794
You could always patch, but nobody ever recommends that.

Related

how to remove offset in responsive mode in bootstrap 4

I have a very simple set up in place, that looks like this:
<div class="row">
<div id="whoarewe" class="offset-2 col-lg-4 col-md-4 col-xs-12 col-sm-12"></div>
<div id="whatwedo" class="col-lg-4 col-md-4 cold-sm-12 col-xs12>
</div>
</div>
The thing is, in responsive mode, the id #whoarewe still has the 2 column offset, therefore is not lined up vertically with #whatwedo. Is there any way I can do this with simply a media query? or is there a bootstrap property that would take care of it in col-xs and col-sm?
I tried to set col-lg-offset-2 and col-sm-offset-0 but this didn't work :(
Thanks.
I came up with a solution that works in my case, basically using a row property called justify-content-around like so:
<div class="row justify-content-around">
<div class="col-lg-4"></div>
<div class="col-log-4></div>
</div>
<div class="row">
<div id="whoarewe" class="col-md-4 offset-md-2"></div>
<div id="whatwedo" class="col-md-4"></div>
</div>
Refer to the documentation for correct offset classes:
https://getbootstrap.com/docs/4.0/layout/grid/#offsetting-columns
Otherwise you can set the column width and do some flex magic by justifying content as per your need
https://getbootstrap.com/docs/4.0/utilities/flex/#justify-content

What is the best way to pass a model to an include file?

I'm learning AngularJs and I got to a small brick wall...
when I want to split items into tabs, my template is exactly the same for all the tabs, the only small change if the model used in the ng-repeat, as an example:
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="tier6">
<div ng-include="'partials/vehicles-6-details.html'"></div>
</div>
<div role="tabpanel" class="tab-pane fade" id="tier8">
<div ng-include="'partials/vehicles-8-details.html'"></div>
</div>
<div role="tabpanel" class="tab-pane fade" id="tier10">
<div ng-include="'partials/vehicles-10-details.html'"></div>
</div>
</div>
This way I have to create 3 exact files, where the template is:
<ul class="list-unstyled list-inline list-tier">
<li ng-repeat="tank in tankInfoLevel6" data-sortby="{{playersByTankId[tank].length}}">
<span class="badge">{{playersByTankId[tank].length}}</span>
<img ng-src="{{tankInfo[tank].image}}" alt="" class="tank-img"
pop-over title="Tank fans" fans="tanksFans[tank]" />
<br><b>{{tankInfo[tank].name_i18n}}</b>
<br>({{tankInfo[tank].type_i18n}})
</li>
</ul>
and the only change is tankInfoLevel6 by tankInfoLevel8 and tankInfoLevel10 respectively.
How can I use a simple file?
I've tried:
<div ng-include="'partials/vehicles-details.html'"
ng-init="tierTanks = tankInfoLevel6"></div>
and also with onLoad and onInclude without any good results.
The output is showing the last tab contents in all tabs, so it seems that it loads all but the last call with tankInfoLevel10 is the one that overrides all the tabs.
Is there a way to make this work neatly?
What about ng-repeat?
<div ng-repeat="tankItem in tankItems">
<div ng-include="'partials/vehicles-details.html'"></div>
</div>
In template use tankItem.
Wouldn't a directive work better here, using an attribute to pass/reference the tankItems list?

Render a collection with different classes one time in two

I am a beginner using AngularJS.
I would like to render a collection in my HTML code, with a specific directive: one item at left, the following one at right, the third one at left etc...
<div ng-repeat="Model in Collection">
<!-- The HTML i need for even iterations -->
<div class="col-xs-2.col-sm-2.col-md-2.col-lg-2.col-xs-offset-2.col-sm-offset-2.col-md-offset-2.col-lg-offset-2">
<img alt="Player" src="{{Model.avatar}}" popover-placement="left">
</div>
<!-- The HTML i need for odd iterations -->
<div class="col-xs-2.col-sm-2.col-md-2.col-lg-2.col-xs-offset-8.col-sm-offset-8.col-md-offset-8.col-lg-offset-8">
<img alt="Player" src="{{Model.avatar}}" popover-placement="right">
</div>
</div>
What is the better way to do that ?
You can take advantage of ng-class-odd and ng-class-even to declare the class of the divs.
<div ng-repeat="Model in Collection">
<div ng-class-even="'col-xs-2.col-sm-2.col-md-2.col-lg-2.col-xs-offset-2.col-sm-offset-2.col-md-offset-2.col-lg-offset-2'"
ng-class-odd="'col-xs-2.col-sm-2.col-md-2.col-lg-2.col-xs-offset-8.col-sm-offset-8.col-md-offset-8.col-lg-offset-8'">
<img alt="Player" src="{{Model.avatar}}" ng-class-even="'left'" ng-class-odd="'right'">
</div>
</div>

angular wizard ng-view and angularui modal

I am building a wizard in angular using the angular-ui bootstrap modal component.
In my main page, I am already using ng-views for navigation.
The goal is to create a modal wizard on one of these pages. As far as I can see,
nested ng-views are not supported. If possible, I would like to keep each step of
the wizard as an external resource.
A terrible way to accomplish this at the moment is something to this effect:
<div id="wizardModal" class="modal hide">
<div class="modal-header">
<div ng-show="isCurrentStep(1)">
<p>Step1 header</p>
</div>
<div ng-show="isCurrentStep(2)">
<p>Step2 header</p>
</div>
<div ng-show="isCurrentStep(3)">
<p>Step3 header</p>
</div>
</div>
<div class="modal-body">
<div ng-show="isCurrentStep(1)">
<p>Step1 body</p>
</div>
<div ng-show="isCurrentStep(2)">
<p>Step2 body</p>
</div>
<div ng-show="isCurrentStep(3)">
<p>Step3 body</p>
</div>
</div>
<div class="modal-footer">
<div ng-show="isCurrentStep(1)">
<p>Step1 footer</p>
</div>
<div ng-show="isCurrentStep(2)">
<p>Step2 footer</p>
</div>
<div ng-show="isCurrentStep(3)">
<p>Step3 footer</p>
</div>
</div>
</div>
Obviously, the above is unacceptable and will create maintenance nightmares.
Is there a clean approach to accomplishing the same effect?
Using ng-include worked like a charm, thanks.
You can find a tutorial about creating a wizard-style app using ng-view and ngRouter here.
I believe this approach is much better since you can have individual controllers per step that inherit the scope from the host form thus keeping all the data but separating the logic.

AngularJS: data-ng-model & data-ng-hide/show

My index.html page is like as follows:
<div id="sidepanel" data-ng-controller="ListCtrl">
<li data-ng-repeat="record in records">
{{record.id}}
<input type="checkbox" data-ng-model="addwidget">
</li>
</div>
<div id="main">
<div data-ng-view></div>
</div>
for this data-ng-view i have another page recordlist.html in that i have following code:
<div data-ng-controller="ListCtrl">
<ul class="design">
<li data-ng-repeat="record in records">
<div data-ng-switch data-on="record.category">
<div data-ng-switch-when="reporting1">
<div id="{{record.id}}" data-ng-show="addwidget">{{record.description}}</div>
</div>
<div data-ng-switch-when="reporting2">
<div id="{{record.id}}" data-ng-hide="addwidget">{{record.description}}</div>
</div>
</li>
</ul>
</div>
My question is i want to show the first div when i check the checkbox & when i uncheck it i want to show the second div.When both of the data-ng-model & data-ng-hide/show are on the same page then it works fine but in my case it present on two different pages.
Is it correct ? How can i implement this. Need Help.Thanks.
The problem is that you are setting addwidget in the first controller, but is trying to use it in the second. Controllers are not singletons.
So, in this situation:
<div id="sidepanel" data-ng-controller="ListCtrl">
...
</div>
<div id="main">
<div data-ng-view>
<div data-ng-controller="ListCtrl">
</div>
</div>
</div>
You got two separated controllers and scopes. And you are setting addwidget in the first trying to read in the second.
You can either bind it to the root scope $root.addwidget or use a service share to the states.
As you have many records, binding directly to root is a problem, as all of them are going to share the same state. So you gonna need an object in the rootScope and bind the option by id $root.addwidget[record.id]. Made a pretty simplified modification here.

Resources