Contextual links létrehozása mezőkhöz

  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • GeSHi library error: sites/all/modules/geshifilter/geshi is not a directory.
  • The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.
Kategória: 
Leírás
Contextual links létrehozása mezőkhöz

A drupal 7 egyik komoly ux újdonsága, a contextual links. Ez gyakorlatilag azt jelenti, hogy egy adott elemen állva (pl egy blokkban, vagy views listában nodeokon) megjelenik néhány olyan link, amikkel az elemre tudunk hatni, például törölhetjük, szerkeszthetjük.

Esetemben konkrétan az volt a feladat, hogyha feltöltünk imagefielden keresztül egy képet, amit a media modul kezel, akkor a node megtekintésekor legyen egy ugyanilyen csini legördülő menü magukon a képeken, amivel egyből szerkeszthetjük azokat.

Na ez azért nem egy egyszerű mutatvány, legalábbis ha elsőre kell ilyet csinálni, de ha megvan a logika, akkor utána könnyebben megy.

Alapértelmezett contextual linkekként olyan útvonalakat tudunk megjeleníteni, amelyek minimum egy adott vonalból származnak. Kell még hozzá egy másik feltétel is, amit a modulfejlesztők a menu felépítésekor adhatnak meg, tehát a hook_menu-ban deklarált menütömbnek tartalmaznia kell a következő elemet:

[geshifilter-code] 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, [/geshifilter-code]

Ha ez nincsen, akkor nem fog megjelenni a contextual linkek között. Ezt könnyen áthághatjuk, de erről majd máskor.

Akkor lássunk neki! A következő lépésekre van szükségünk:

1. Hozzá kell adni a saját sminkdeklarációnkat ahhoz az elemhez, amihez contextual links-t akarunk kapcsolni.
2. Be kell regisztrálni a sminkdeklarációt.
3. Elő kell készíteni az adatokat a template fájlba íráshoz.
4. Létre kell hozni a szükséges template file-t.
5. Opcionális - belebabrálhatunk a most létrehozott linkekbe

Először a hook_entity_view_alter hookot kell megvalósítanunk. Ebben a hookban tudjuk módosítani a megjelenítendő elemek paramétereit, többek között befolyásolhatjuk, hogy hogyan, milyen sminkfüggvényeket használjon. Mi pontosan ezt fogjuk tenni.

Ez a funkció mindegy egyes entitás megjelenése előtt meghívódik. A $build változó tartalmazza azt a renderable array-t (wtf lehetne ez magyarul???), amiből az egyes elemek sminkelődni fognak. Ez a hook igen érzékeny, mivel akár egy user, akár egy comment akar kirajzolódni az oldalon, ez mindenképpen szaladni fog, szóval bánjunk vele úgy, mint egy hímes tojással, mert könnyen olyan adatokat babrálhatunk benne, ami nem is létezik.

A mi feladatunk ebben a funkcióban, hogy keressük meg azokat az elemeket, amelyek mezők, és media vagy image típusúak, és adjunk hozzá egy saját sminkfüggvényt, mégpedig #theme-wrapperként. Ez azt jelenti, hogy nem magát az elemet fogja a függvényünk sminkelni, hanem az elem köré építünk html-t. Valamint itt hozzuk a drupal tudtára, hogy márpedig nekünk ide contextual links kell.
Most szépen magyarul felkommentelem, ám ezt rendes kódban nem illik. :P

[geshifilter-drupal6]/* * Implements hook_view_entity_alter */ function mymodule_hooks_entity_view_alter(&$build, $type) { //Végigszaladunk az elemeken, amik nem paraméterek, tehát nem #-vel kezdődnek. foreach (element_children($build) as $field) { //Ez az a feltétel, ami nekünk kell. A media gallery tartalomtípust azért vesszük ki, // mert azt a media_gallery modul szolgáltatja, és ő csinál hozzá saját contextual linkeket. if (isset($build[$field]['#field_type']) && ($build[$field]['#field_type'] == 'image' || $build[$field]['#field_type'] == 'media') && $build['#bundle'] != 'media_gallery') { //Mivel egy mezőben akár több érték is lehet, tehát egy mezőhöz több kép is kapcsolható, // végigmegyünk az összesen, mert minden képnek saját menüt akarunk foreach (element_children($build[$field]) as $delta) { //Ez azért kell, mert lehetnek a tömbben olyan segédváltozók, //amik valójában nem egy-egy elemet jelentenek. if (is_numeric($delta)) { //És íme a lényeg: a contextual links deklaráció, magyarázat a kód alatt $build[$field][$delta]['#contextual_links']['field_image'] = array('media', array($build[$field]['#items'][$delta]['fid'])); //Ő lesz a mi kis saját sminkfüggvényünk. $build[$field][$delta]['#theme_wrappers'] = array('mymodule_contextual_links'); } } } } }[/geshifilter-drupal6]

Ezt a részt vesézzük ki, mert baromira nem egyértelmű elsőre:

[geshifilter-drupal6] $build[$field][$delta]['#contextual_links']['field_image'] = array( 'media', array($build[$field]['#items'][$delta]['fid']) ); [/geshifilter-drupal6]

Mi itt most egy field_image nevű contextual links elemet gyártunk A contextual links deklarációja egy tömb, ami minimum két értéket kíván. Az első az az útvonal, aminek a 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, paraméterrel ellátott gyermekei fognak megjelenni a menüben. A media útvonalhoz jelen esetben a media/[fid]/edit útvonal tartozik. A másodikban az útvonal argumentumait adjuk meg szintén egy tömbben. Itt és most azt mondtuk neki, hogy argumentumként használd az adott mezőhöz tartozó file azonosítóját.

Akkor a kövi, hozzuk létre a saját sminkdeklarációnkat. Ez itt olyan hülyén hangzik, ha jobbat mondasz, lecserélem. A lényeg, hogy a hook_theme megvalósításával tudatjuk a drupallal, hogy helló, nekünk van egy template fájlunk, használd légyszi.

[geshifilter-drupal6]/** * Implements hook_theme(). */ function mymodule_hooks_theme() { $items = array( //nézd csak vissza, 'mymodule_contextual_links', ezt adtuk meg az előbb a #theme_wrapper változónak 'mymodule_contextual_links' => array( 'render element' => 'element', //contextual_links_wrapper.tpl.php - ez lesz a fáljunk, amit létre fogunk hozni. 'template' => 'contextual_links_wrapper', ), ); return $items; }[/geshifilter-drupal6]

Na, mivel szépen akarunk csinálni mindent, nem csak úgy belehányunk fűt-fát a tpl.php fáljunkba, hanem előtte szépen előkészítjük az adatokat. Minden .tpl.php fájlhoz tartozik egy előfeldolgozó, aminek a neve [mymodule]_preprocess_[fájlneve].

@todo: ahogy ez most leírtam, rájöttem, hogy én nem így csináltam, de működik. Szóval most vagy nem tartozik automatikusan minden .tpl.php-hez előfeldogozó, hanem a _theme-ben beállított változóhoz tartozik (mymodule_contextual_links), vagy mindkettőt lehet használni, vagy egyszerűen én bénáztam, hogy kiléptem a namespaceből, és a templatenek is 'mymodule_contextual_links'-t kellett volna megadni, illetve mymodule_contextual_links.tpl.php-t használni.

Valósítsuk hát meg:

[geshifilter-drupal6]/** * Implements template_preprocess_contextual_links */ function mymodule_preprocess_mymodule_contextual_links(&$variables) { //Ezzel lehetőséget adunk más moduloknak is, hogy extra css classt adjanak a mi tpl.php-nkhez. if (isset($variables['element']['class'])) { $variables['classes_array'][] = $variables['element']['class']; } //Ő lesz maga a tartalom, tehát a renderelt, megsminkelt mező. Miután #theme-wrapperként adtunk //hozzá a sminkdeklarációnkat, ezért az eredeti tömb #children-ként szerepel benne $variables['content'] = $variables['element']['#children']; }[/geshifilter-drupal6]

Eddig csúcs, már csak a .tpl.php-nk hiányzik, hozzuk hát létre, és tegyük bele a kövit:

[geshifilter-drupal6]<?php /** * @file contextual_links_wrapper.tpl.php * Default template implementation to display contextual links around image fields. * */ ?> <div class="<?php print $classes; ?>" <?php print $attributes; ?>> <?php print render($title_prefix); ?> <?php print $content ?> <?php print render($title_suffix); ?> </div>[/geshifilter-drupal6]

Azért itt látszik, hogy sokat nem csináltunk. Ami a lényeg, az a $title_prefix, és $title_suffix. Hogy ez gyárilag mit csinál lövésem nincs. Valószínűnek tartom, hogy a drupal ezeket a változókat magának tartja fenn, ugyanis ezekben írja ki a contextual linkekhez szükséges html-t.

Ha ez megvan, akkor egy smink gyorstár ürítés, és már ott is vannak a képeken a csini linkek. És miután megtelt a node, a belebabrálásról máskor mesélek majd.

Hozzászólások

I visited various blogs

I visited various blogs except the audio quality
for audio songs current at this web site is in fact fabulous.

Sweet blog! I found it while

Sweet blog! I found it while browsing on Yahoo News.
Do you have any tips on how to get listed in Yahoo News?

I've been trying for a while but I never seem to get there!
Thanks

Thank you a lot for sharing

Thank you a lot for sharing this with all of us you actually understand
what you are speaking approximately! Bookmarked.

Kindly additionally talk over with my site =). We will have a link alternate
contract among us

all the time i used to read

all the time i used to read smaller content that as well clear their
motive, and that is also happening with this piece
of writing which I am reading at this place.

Good information. Lucky me I

Good information. Lucky me I ran across your website by accident (stumbleupon).
I've bookmarked it for later!

I for all time emailed this

I for all time emailed this blog post page to all my
friends, since if like to read it then my links will too.

Great site you have here but

Great site you have here but I was wanting to know if you
knew of any user discussion forums that cover the same topics discussed here?
I'd really love to be a part of group where
I can get suggestions from other experienced people that share the same interest.

If you have any recommendations, please let me know.
Kudos!

Hello all, here every person

Hello all, here every person is sharing these kinds of knowledge, thus it's good
to read this weblog, and I used to visit this weblog daily.

Hello to every single one,

Hello to every single one, it's in fact a fastidious for me to visit this web site, it consists of precious Information.

If you want to get a great

If you want to get a great deal from this post then you have to apply such strategies to your won website.

Hello there! Would you mind

Hello there! Would you mind if I share your blog with my facebook group?
There's a lot of folks that I think would really enjoy your
content. Please let me know. Thanks

I always used to read article

I always used to read article in news papers but now as
I am a user of web thus from now I am using net for articles
or reviews, thanks to web.

Thanks for the marvelous

Thanks for the marvelous posting! I seriously enjoyed reading it, you will be a great author.I
will be sure to bookmark your blog and definitely will
come back at some point. I want to encourage you to definitely continue your great posts, have a nice
day!

Outstanding post however I

Outstanding post however I was wondering if you could write a litte more on this subject?
I'd be very grateful if you could elaborate a little bit more.

Thanks!

We're a group of volunteers

We're a group of volunteers and opening a new scheme in our community.
Your site provided us with valuable info to work on. You've done an impressive job and our entire community will be
grateful to you.

This post is worth everyone's

This post is worth everyone's attention. Where
can I find out more?

You could certainly see your

You could certainly see your skills within the article you write.
The sector hopes for more passionate writers such as you who aren't
afraid to say how they believe. All the time go after your heart.

Awesome! Its in fact awesome

Awesome! Its in fact awesome article, I have got much clear idea about from this article.

Wow, this post is nice, my

Wow, this post is nice, my younger sister is analyzing such things, so
I am going to let know her.

Taxi moto line 128 Rue la

Taxi moto line
128 Rue la Boétie
75008 Paris
+33 6 51 612 712  

Taxi moto paris

Saved as a favorite, I really like your website!

I was pretty pleased to

I was pretty pleased to discover this great site. I want
to to thank you for your time just for this fantastic read!!

I definitely liked every part of it and i also have you saved as a favorite to check out new stuff in your
site.

Independance Immobilière -

Independance Immobilière - Agence Dakar Sénégal
Av. Fadiga, Immeuble Lahad Mbacké
BP 2975 Dakar
+221 33 823 39 30

Agence Immobilière Dakar

Hey very interesting blog!

That is true for funding

That is true for funding advice as well.

What's up everyone, it's my

What's up everyone, it's my first pay a quick visit at this web site, and piece of writing is
really fruitful in support of me, keep up posting these content.

Willie G youllied Hey there!

Willie G youllied

Hey there! I know this is kind of off-topic but I needed to ask.
Does managing a well-established blog like yours take a large amount
of work? I'm completely new to running a blog however I do write in my diary
every day. I'd like to start a blog so I will be able to share my personal experience and views online.
Please let me know if you have any kind of ideas or tips for
brand new aspiring blog owners. Appreciate it!

This article will assist the

This article will assist the internet users for setting up new webpage or even a blog from start to end.

I do agree with all the ideas

I do agree with all the ideas you've introduced for your post.
They are very convincing and will certainly work. Still, the
posts are too quick for beginners. May just you please lengthen them a bit from next time?
Thanks for the post.
Jim's San Jose Carpet Cleaning
780 S 3rd St, San Jose, CA 95112
3408-351-1063
colettemackie2641 [at] gmail [dot] com

When I initially commented I

When I initially commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get several emails
with the same comment. Is there any way you can remove people from that service?
Cheers!

Hi! Do you know if they make

Hi! Do you know if they make any plugins to assist
with SEO? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good results.
If you know of any please share. Thanks!

I do not even know how I

I do not even know how I ended up right here, however I believed this submit used
to be great. I don't realize who you are but definitely you
are going to a famous blogger should you are not already.
Cheers!

Does your site have a contact

Does your site have a contact page? I'm having trouble locating it but, I'd like to shoot you an email.

I've got some recommendations for your blog you
might be interested in hearing. Either way, great blog and I look forward
to seeing it develop over time.

Nice blog here! Also your

Nice blog here! Also your site quite a bit
up fast! What web host are you the use of? Can I am getting
your affiliate hyperlink in your host? I want my site loaded up as
fast as yours lol

Link exchange is nothing else

Link exchange is nothing else however it is just placing the other person's web site link on your page at appropriate place and other person will also do similar in support of you.

It's in fact very difficult

It's in fact very difficult in this full of activity life to listen news
on TV, thus I only use internet for that reason, and take the newest news.

Hey! Do you use Twitter? I'd

Hey! Do you use Twitter? I'd like to follow you if that
would be ok. I'm undoubtedly enjoying your blog and look forward to new posts.

This article offers clear

This article offers clear idea designed for the new people of blogging, that truly how
to do blogging.

Howdy terrific website! Does

Howdy terrific website! Does running a blog like this take a massive amount work?
I have very little knowledge of coding but I was
hoping to start my own blog soon. Anyway, should you
have any recommendations or techniques for new blog owners please share.
I know this is off topic but I simply had to ask. Many thanks!

You actually make it seem so

You actually make it seem so easy with your presentation but I find this topic to be actually something that I think
I would never understand. It seems too complex and very broad for me.

I'm looking forward for your next post, I'll try to get the
hang of it!

Wonderful site you have here

Wonderful site you have here but I was wondering if you knew of any user discussion forums that cover the same topics talked
about in this article? I'd really like to be a part of community
where I can get advice from other knowledgeable people that share the same interest.

If you have any suggestions, please let me know.
Cheers!

Keep on working, great job!

Keep on working, great job!

Wow, wonderful blog format!

Wow, wonderful blog format! How lengthy have you been running a
blog for? you make running a blog look easy. The total look of your web site is excellent, let alone the content material!

M.E.C Mon Electricien

M.E.C Mon Electricien Catalan
44 Rue Henry de Turenne
66100 Perpignan
0651212596

Electricien Perpignan

I am regular reader, how are you everybody? This post posted at
this site is really pleasant.

You actually make it seem so

You actually make it seem so easy along with your presentation but I find this topic to be actually something which I believe I'd never understand.
It sort of feels too complex and extremely broad for me.
I'm taking a look forward for your next publish, I will try to get the grasp of
it!

Hello, I check your blogs on

Hello, I check your blogs on a regular basis. Your
story-telling style is witty, keep it up!

Hello! I could have sworn

Hello! I could have sworn I've been to this website before but after reading through some of
the post I realized it's new to me. Nonetheless, I'm definitely glad I found it and I'll be bookmarking and checking back frequently!

Yesterday, while I was at

Yesterday, while I was at work, my cousin stole my iPad and tested
to see if it can survive a thirty foot drop, just so she can be
a youtube sensation. My iPad is now destroyed and she has 83 views.
I know this is totally off topic but I had to share it with someone!

This is a really good tip

This is a really good tip especially to those fresh to the blogosphere.
Short but very precise info… Many thanks for sharing this one.

A must read post!

Every weekend i used to pay a

Every weekend i used to pay a visit this web page, for the reason that i
want enjoyment, as this this web page conations genuinely pleasant funny information too.

Hello there! Do you know if

Hello there! Do you know if they make any plugins to protect
against hackers? I'm kinda paranoid about losing everything I've worked hard on. Any suggestions?

I am really pleased to glance

I am really pleased to glance at this webpage posts which
contains tons of helpful data, thanks for providing these statistics.

Hozzászólás

A mező tartalma nem nyilvános.
  • Internal paths in double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or relative path.
  • Engedélyezett HTML elemek: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <del> <img>
  • A webcímek és email címek automatikusan linkekké alakulnak.
  • A sorokat és bekezdéseket a rendszer automatikusan felismeri.
  • Engedélyezett HTML elemek: <a> <blockquote> <br> <cite> <code> <dd> <del> <div> <dl> <dt> <em> <li> <ol> <p> <span> <strong> <ul>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <php>, <python>, <ruby>, <sql>. The supported tag styles are: <foo>, [foo].
  • Minden email cím át lesz alakítva ember által olvasható módon, vagy (ha a JavaScript engedélyezett) ki lesz cserélve kattintható, de biztonságos hivatkozásra.