layoutData, new theme system and Drupal Intergration

yaus831

Joined: 2004-10-20
Posts: 11
Posted: Mon, 2005-07-25 04:51

Now that layoutData is gone in GalleryEmbed, drupal integration look a bit weird now:

- I guess GalleryCapabilities::set('showSidebar', false) no longer work, it should use GalleryCapabilities::set('showSidebarBlocks', false);
- It seem that GalleryCapabilities::set('showPathbar', false); also no longer work, any workaround on this?
- In Drupal integration, we used to use the layoutData to set the page title as well as building the breadcrumb in Drupal, using the following code:

    if (isset($result['layoutData'])) {
      $urlGenerator =& $GLOBALS['gallery']->getUrlGenerator();
      $breadcrumb = array(l(t('Home'), ''));
      foreach ($result['layoutData']['parents'] as $parent) {
        $breadcrumb[] = '<a href="'.$urlGenerator->generateUrl(array('itemId' => $parent['id'])) .'">'.$parent['title']."</a>";
      }
      drupal_set_breadcrumb($breadcrumb);
      drupal_set_title($result['layoutData']['item']['title']);
    }

Is there any way we can do it in the new theme system?

- Similiar, we also use the layoutData to build the navigation in Drupal, I guess now we can use the $data['showSidebarBlocks'] and extract the navigation block, but we no longer has the fine grain control on the layout because it will have the html code in there as well, and it become pretty ugly because it look a lots different than the rest of the site. (Drupal integration use the following code to generate the navigation:)

         if (!$result['isDone'] && $result['layoutData']) {
			  $content = "<div class='menu'><ul>";
            $list = array();
            foreach ($result['layoutData']['itemLinks'] as $itemLink) {
              $list[] = '<a href="'.$itemLink['url'] .'">'.$itemLink['text'] ."</a>\n";
            }
            foreach ($result['layoutData']['systemLinks'] as $systemLink) {
              $list[] = '<a href="'.$systemLink['url'] .'">'.$systemLink['text'] ."</a>\n";
            }
			$content = $content . "</ul></div>";
            $block['subject'] = t('gallery');
            $block['content'] = theme('item_list', $list);
	    
          }
        }

Anyway i can extract this information?

BTW, b4 rocks.

Regards,
-SY

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-07-25 06:59

- take a look at the sticky topic "Embedding and integration". i announce there changes.
e.g. you'll find there the sidebar stuff.

- pagetitle: use list ($title, $css, $js) = GalleryEmbed::parseHead($headHtml);

use css to change the look of the sidebar blocks / navigation. noone said you'd have to use the standalone, vanilla css for drupal.

i'd also recommend what the wpg2 devs did: develop a g2 theme for drupal.

 
yaus831

Joined: 2004-10-20
Posts: 11
Posted: Mon, 2005-07-25 09:14

thx for the information on the pagetitle.

I did look at the "Embedding and integration" thread before i post this but I could not find the information regarding how to retrieve the layoutData as before ( i guess it is gone). So that's why I post this message.

While I understand that develop a theme specify for your site is the best solution. (I am running a modify version of Matrix since b3). IMHO: I still think that layoutData provide a more flexible option for me to tighyly integrate with the CMS, in this case, Drupal.

Just my 2 cents.

Anyway, go back to create my new theme then

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-07-25 09:59

yaus831, the layoutData approach was unique to the drupal integration. it was a hack, not documented etc. the same applies to the breadcrumb thing.

I understand that it's more flexible to assemble your own html. but it's also more demanding for the integration authors. if every integration has to retrieve the data from g2 and then generate it's own html, it would definitely very powerful, but it would take ages until an integration is finished.
so i'd see this layoutData (now it would rather be themeData) as a plus.

and i'd rather have some clearly defined API to get what you want instead of supplying the whole themeData, because the internal structure of the themeData can change without notice.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-07-25 10:26

if you want to experiment a little, add
$data['themeData'] =& $template->getVariableByReference('theme');
right after line 313 of main.php

you can use var_dump($data['themeData']); to see what information is available.

 
yaus831

Joined: 2004-10-20
Posts: 11
Posted: Mon, 2005-07-25 10:32
valiant wrote:
I understand that it's more flexible to assemble your own html. but it's also more demanding for the integration authors. if every integration has to retrieve the data from g2 and then generate it's own html, it would definitely very powerful, but it would take ages until an integration is finished.
so i'd see this layoutData (now it would rather be themeData) as a plus.

Why not provide both then? I understand that the gallery should responsible to handle gallery related request, encapsulate all the layout logic controlled by the theme system and return the output to external system. But why not provide both option so that if people want more flexibility, they can still retrieve that information throught $themeData or something, and aware the risk that the $themeData structure may change without notice. (I guess the structure is located in here; GalleryTheme::loadCommonTemplateData())

I can probably still achieve what I want previously by using pure CSS and custom theme, but it just look like more work: Drupal output its own breadcrumb, and gallery2 will output breadcrumb as well, in this case I will either disable the drupal breadcrumb and use the G2 breadcrumb when it is showing gallery2 related item or modify the theme in gallery 2 and use some css 'magic' to merge this 2 div/breadcrumb together. I guess it will work in the end, but it just look more complicated for something so simple before. (another way will be parse the bodyhtml, get the information we need (like the parseHead), and retrieve that information.)

I just track down the code in main.php, I guess i will do the hack on this one when I have time :). (Or if we have GalleryEmbed::getThemeData() also sound nice :) )

Anyway, just my 2 cents.

Regards,
-SY

 
yaus831

Joined: 2004-10-20
Posts: 11
Posted: Mon, 2005-07-25 10:34
valiant wrote:
if you want to experiment a little, add
$data['themeData'] =& $template->getVariableByReference('theme');
right after line 313 of main.php

you can use var_dump($data['themeData']); to see what information is available.

lol, was typing the reply when you post this. Thx for the information. I will just do that.

Thanks for the great work in G2.

Regards,
SY
http://www.ocean.hk

 
yaus831

Joined: 2004-10-20
Posts: 11
Posted: Mon, 2005-07-25 11:53

got it work now.. many thx.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-07-25 12:43

i'm curious, how does your code look like?

 
yaus831

Joined: 2004-10-20
Posts: 11
Posted: Mon, 2005-07-25 13:01

I have added the suggested line in main.php, then in gallery.module (the drupal integration) in function _gallery_handle_request()

function _gallery_handle_request() {
  static $result;

  if (!$result) {
    _gallery_init();

    GalleryCapabilities::set('showSidebarBlocks', false);
    $result = GalleryEmbed::handleRequest();
    list ($title, $css, $js) = GalleryEmbed::parseHead($result['headHtml']);
    drupal_set_title($title);    
    if (isset($result['themeData'])) {
      $urlGenerator =& $GLOBALS['gallery']->getUrlGenerator();
      $breadcrumb = array(l(t('Home'), ''));
      foreach ($result['themeData']['parents'] as $parent) {
	      $breadcrumb[] = '<a href="'.$urlGenerator->generateUrl(array('itemId' => $parent['id'])) .'">'.$parent['title']."</a>";
      }
      drupal_set_breadcrumb($breadcrumb);
    }
    
  }

  return $result;
}

then in gallery_block

      case 0: 
        if (arg(0) == 'gallery') {
          $result = _gallery_handle_request();
	  
          
          if (!$result['isDone'] && $result['themeData']) {
		  $urlGenerator =& $GLOBALS['gallery']->getUrlGenerator();
		  $content = "<div class='menu'><ul>";
		  if (is_array($result['themeData']['itemLinks'])){
			  foreach ($result['themeData']['itemLinks'] as $itemLink) {
				  $content = $content . '<li class="leaf"><a href="'.$urlGenerator->generateUrl($itemLink['params']) .'">'.$itemLink['text'] ."</a></li>\n";
			  }
		  }
		  if (is_array($result['themeData']['systemLinks'])){
			  foreach ($result['themeData']['systemLinks'] as $systemLink) {
				  $content = $content . '<li class="leaf"><a href="'.$urlGenerator->generateUrl($systemLink['params']) .'">'.$systemLink['text'] ."</a></li>\n";
			  }
		  }
		  $content = $content . "</ul></div>";
		  $block['subject'] = t('gallery');
		  $block['content'] = $content;
          }
        }
        break;

The code look pretty much the same as before (b3), except that 'link' is no longer available in $systemLink and $itemLink and need to generate using the urlGenerator.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Mon, 2005-07-25 13:13

ok :)

IMO you could achieve almost the same if we offered GalleryEmbed::getBlockHtml('core.ItemLinks');

and then you'd use CSS to make it look like you want it to, given that the <div> around the itemLinks is selectable etc.

the same goes for breadcrumb and systemlinks.

 
lvthunder

Joined: 2003-09-12
Posts: 808
Posted: Thu, 2005-08-11 15:18

Is it still after line 313 in main.php that we have to add this?
$data['themeData'] =& $template->getVariableByReference('theme');

Also if this is the way we have to do this in Drupal can this be added to a module or something so that when we upgrade Gallery we don't have to add this line everytime.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-08-11 16:49

yes you still have to do this.
please file a feature request. sure i could just add this line to main.php, but IMO we should solve this in a better way, and this will take some time.

 
lvthunder

Joined: 2003-09-12
Posts: 808
Posted: Thu, 2005-08-11 18:20

So it goes between these two lines

	    if ($ret->isError()) {
		return array($ret->wrap(__FILE__, __LINE__), null);

I just wanted to make sure that the lines in main.php changed in the last few weeks since I'm using RC1.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-08-11 20:00

no, not there.

add it after these two lines:

$data = $theme->splitHtml($html, $results);
$data['isDone'] = false;

 
lvthunder

Joined: 2003-09-12
Posts: 808
Posted: Thu, 2005-08-11 20:40

It works now. Thanks valiant and yaus831. As you requested valiant I created RFE #1257054.

 
YAFA

Joined: 2006-01-12
Posts: 10
Posted: Fri, 2006-10-06 12:47

Hi,

I am using a fresh Drupal v4.7.3- and Gallery 2.1.1-Installation. I am using the Hybrid-theme, because it fits very good into the Drupal-Layout and the Hybrid-pictureviewer is pretty handy. I got a php-error logged in drupal pointing to gallery.module line 218 wich starts the following foreach:

if (isset($result['themeData'])) {
   $urlGenerator =& $GLOBALS['gallery']->getUrlGenerator();
   $breadcrumb = array(l(t('Home'), ''));
   foreach ($result['themeData']['parents'] as $parent) {
      $parent_title = $parent['title'];
      // Simple strip of bbcode (italics) 
      $parent_title = str_replace("", "<i>", $parent_title);
      $parent_title = str_replace("", "</i>", $parent_title);
      $breadcrumb[] = '<a href="'.$urlGenerator->generateUrl(
         array('itemId' => $parent['id'])) .'">'.$parent_title."</a>";
   }

The URL this error was produced from, is this one:
http://www.domain.tld/index.php?q=gallery&g2_itemId=123&g2_detail=1

The error is an invalid argument supplied for foreach. Its reason is, that for this URL $result['themeData'] has keys, but no ['parents']. For not removing the $breadcumb = array...-Code I just added another if-block around the for-block:

if( isset($result['themeData']['parents']) ) {
   foreach ($result['themeData']['parents'] as $parent) {
   ...
}

The error is gone and, as far as I can see right now, the code has no further effect on the module. I wrote this in a little naiv way, because I actually don't know neither Drupal-Coding, nor Gallery2-Coding. Just tried some direct PHP-correction for getting my installation to work.

so long,
Felix Lieb
--
YAFA - Yet Another Forum Account

 
senior_banana

Joined: 2006-10-09
Posts: 1
Posted: Mon, 2006-10-09 08:03

How can I get this line:

$urlGenerator =& $GLOBALS['gallery']->getUrlGenerator();

to use the gallery UrlRewrite functionality so shorturls are used in the Drupal breadcrumb?

 
kiz_0987

Joined: 2005-02-27
Posts: 189
Posted: Tue, 2006-10-10 17:54

The latest CVS gallery module supports short URLs in the breadcrumb and is 4.7 compatible.