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

Hi there fantastic blog! Does

Hi there fantastic blog! Does running a blog like this take a great deal of work? I have very little understanding of programming however I was hoping to start my own blog soon. Anyway, if you have any ideas or tips for new blog owners please share. I understand this is off topic however I just wanted to ask. Appreciate it!|

Greetings from Florida! I'm

Greetings from Florida! I'm bored at work so I decided to check
out your site on my iphone during lunch break. I love
the knowledge you present here and can't wait to
take a look when I get home. I'm shocked at how fast your blog loaded on my mobile
.. I'm not even using WIFI, just 3G .. Anyhow, superb site!

Ridiculous story there. What

Ridiculous story there. What happened after? Thanks!

It's going to be end of mine

It's going to be end of mine day, however before end I am reading this great piece
of writing to increase my knowledge.

I just couldn't leave your

I just couldn't leave your website prior to suggesting that I actually enjoyed the standard info an individual supply to your guests? Is going to be back continuously in order to check out new posts|

Thanks for one's marvelous

Thanks for one's marvelous posting! I seriously enjoyed
reading it, you're a great author.I will make sure to bookmark your blog and will eventually come back
someday. I want to encourage yourself to continue
your great job, have a nice afternoon!

Howdy! Someone in my Facebook

Howdy! Someone in my Facebook group shared this site with
us so I came to look it over. I'm definitely loving the information. I'm bookmarking and will
be tweeting this to my followers! Excellent blog and fantastic style and design.

I love your blog.. very nice

I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to
do it for you? Plz reply as I'm looking to create my own blog and would like to know where u got this
from. many thanks

Hello there! I know this is

Hello there! I know this is somewhat off topic but I was wondering if you knew where I could
get a captcha plugin for my comment form? I'm using the same blog platform
as yours and I'm having trouble finding one? Thanks a lot!

I enjoy what you guys tend to

I enjoy what you guys tend to be up too. This kind of clever work and
reporting! Keep up the very good works guys I've added you guys to my personal blogroll.

Hi, i think that i saw you

Hi, i think that i saw you visited my blog so i came to “return the favor”.I am trying to find things to improve my site!I suppose its ok to use some of your ideas!!|

Link exchange is nothing else

Link exchange is nothing else except it is just placing the other person's
blog link on your page at suitable place and other person will also
do similar in favor of you.

I every time emailed this

I every time emailed this weblog post page to all my friends, since if like to read
it after that my contacts will too.

You really make it seem so

You really make it seem so easy with your presentation but I find this matter to be actually something which I think I would never understand. It seems too complex and very broad for me. I'm looking forward for your next post, I will try to get the hang of it!|

It's actually a nice and

It's actually a nice and useful piece of info. I'm satisfied that you shared this useful information with us.
Please keep us up to date like this. Thank you for sharing.

each time i used to read

each time i used to read smaller articles or reviews which as well clear their motive, and that is
also happening with this piece of writing which I am reading now.

WOW just what I was searching

WOW just what I was searching for. Came here by searching for %meta_keyword%|

Hello, I want to subscribe

Hello, I want to subscribe for this webpage to get most
up-to-date updates, thus where can i do it please help.

I love what you guys are

I love what you guys are usually up too. This
sort of clever work and coverage! Keep up the good works guys I've added
you guys to my personal blogroll.

I enjoy what you guys tend to

I enjoy what you guys tend to be up too. This type of clever work and reporting!
Keep up the awesome works guys I've incorporated you guys to blogroll.

This information is

This information is priceless. When can I find out more?|

Appreciating the persistence

Appreciating the persistence you put into your website and in depth information you offer.
It's great to come across a blog every once in a while
that isn't the same outdated rehashed information. Excellent read!
I've saved your site and I'm including your RSS feeds to my
Google account.

It's going to be end of mine

It's going to be end of mine day, but before ending I am reading this wonderful piece of writing to increase my know-how.

Hello there! Do you know if

Hello there! 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 gains. If you know of any please share. Thank you!

You actually make it seem so

You actually make it seem so easy with your presentation but
I find this topic to be really something which I think I would never understand.
It seems too complex and extremely broad for me. I'm
looking forward for your next post, I will try to get the hang of it!

This post provides clear idea

This post provides clear idea in favor of the new users of blogging, that truly how to do blogging.|

whoah this blog is

whoah this blog is magnificent i like reading your posts.
Keep up the great work! You understand, many people are
looking round for this info, you can aid them greatly.

What's up to all, how is all,

What's up to all, how is all, I think every one is getting
more from this web site, and your views are fastidious in favor of new users.

It is appropriate time to

It is appropriate time to make some plans for the longer term and
it's time to be happy. I've learn this publish and if I may
I wish to suggest you some attention-grabbing issues or advice.
Maybe you could write subsequent articles referring to this article.
I wish to learn even more issues approximately it!

Hello everyone, it's my first

Hello everyone, it's my first pay a quick visit at this web site, and article is in fact fruitful designed for me, keep up posting these articles or reviews.|

Thank you, I have recently

Thank you, I have recently been searching for info approximately this
subject for ages and yours is the greatest I have discovered so far.
But, what concerning the bottom line? Are you sure concerning
the source?

Do you have a spam issue on

Do you have a spam issue on this site; I also am a blogger, and I was wondering your situation;
many of us have created some nice methods and we are looking to exchange strategies with others, be sure
to shoot me an email if interested.

Hey there! I just want to

Hey there! I just want to offer you a big thumbs up for the great information you have right
here on this post. I will be coming back to your web site for more soon.

Greetings! Very useful advice

Greetings! Very useful advice in this particular post!
It is the little changes that produce the largest changes.
Thanks a lot for sharing!

It's impressive that you are

It's impressive that you are getting ideas from this article as well as from our discussion made at this time.|

Do you have a spam issue on

Do you have a spam issue on this site; I also
am a blogger, and I was curious about your situation; we have created some nice practices
and we are looking to swap strategies with other folks, please shoot me an e-mail if interested.

I do not know if it's just me

I do not know if it's just me or if perhaps everyone else experiencing issues with your site.
It appears as if some of the written text within your posts are
running off the screen. Can somebody else please provide feedback and let me
know if this is happening to them as well?
This could be a problem with my web browser because I've had this happen previously.

Thank you

I want to to thank you for

I want to to thank you for this great read!! I absolutely loved every bit of it. I have got you bookmarked to look at new stuff you post…|

For most recent news you have

For most recent news you have to pay a quick visit
web and on world-wide-web I found this site as a most excellent
web page for most up-to-date updates.

I've been exploring for a

I've been exploring for a little bit for any high-quality
articles or weblog posts in this kind of space . Exploring in Yahoo I ultimately stumbled upon this web site.
Reading this information So i am happy to show that I've an incredibly just
right uncanny feeling I discovered just
what I needed. I most no doubt will make sure to do not put out of your mind this web site and give it a look on a relentless
basis.

It's going to be finish of

It's going to be finish of mine day, but before ending I am reading this impressive paragraph to increase my experience.|

After I originally commented

After I originally commented I appear to have clicked the -Notify me when new comments are added- checkbox and from now on whenever a
comment is added I get four emails with the same comment. Is there an easy method you are
able to remove me from that service? Kudos!

Thank you for any other

Thank you for any other informative site. The place else may just I get
that type of info written in such a perfect
means? I have a project that I'm simply now working on, and I've been on the glance out for such
information.

I'm truly enjoying the design

I'm truly enjoying the design and layout of your site. It's a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a developer to create your theme? Superb work!|

Thanks , I have just been

Thanks , I have just been searching for info approximately this subject for ages and yours is the greatest I have found out till now.

However, what about the conclusion? Are you positive concerning the source?

I like what you guys are up

I like what you guys are up too. Such clever work and reporting!
Keep up the excellent works guys I've added you guys to our
blogroll.

Hi there to all, because I am

Hi there to all, because I am actually eager of reading this website's post to be updated daily.
It includes good information.

What's up to every one, the

What's up to every one, the contents present at this web site are actually amazing for people experience, well, keep up the nice work fellows.|

Hi, I think your site might

Hi, I think your site might be having browser compatibility issues.
When I look at your website in Opera, it looks fine but when opening in Internet Explorer, it
has some overlapping. I just wanted to give you a quick heads up!
Other then that, awesome blog!

What's up colleagues, how is

What's up colleagues, how is all, and what you desire
to say about this article, in my view its genuinely amazing designed for me.

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.