Wednesday, December 4, 2013

Day 14: Day 2 of (almost) nothing works

The log entry for Day 13 has been excised, since nothing worked yesterday when I tried to follow the "Praxiswissenschaft" tutorial for setting up editor permissions. The editors I set up can login to the backend and see the various modules I've allowed them to, but no pages. NO pages. Just an empty page-tree. I spent most of the day going over the tutorial again and again, without success. After a Git tutorial, I gave up on the permissions and moved on the preview the chapter on TemplaVoila, which is what I'm implementing today. I felt so unproductive yesterday that I went home early and did a Code School class at home on new features in HTML5 and CSS3. It was easy and fun, finally, as we say in German, an "Erfolgserlebniss".

Today I'm setting up my Typo3 site to work with TemplaVoila. I find it so complicated that I wonder how I will procede without the explicit instructions from the book. Also - guess what - it doesn't work. Where I'm supposed to see a site like the one I built, with no content, I just see a light blue page. Inside the body tags there is nothing. I wonder if I picked the wrong div tag at the beginning of the tutorial? The screenshot in the book showed three and I only had two: I picked the top one.

Two good things today, in any case, include getting to look at the models for someone else's project, and got to help someone with a mail problem in PHP (Erfolgserlebniss).

Going back to the beginning of the tutorial, I recheck my first selected <div> tag - the ID matches. In the preview within the "TemplaVoila" module, everything looks the way it should. WTF doesn't it work on the frontend, then?

Post-lunch: I found the problem in my TypoScript for the Template for the root page of the TemplaVoila site. I had a typo, namely an "l" where a "1" should have been:

page = PAGE
page {
  includeCSS.style = fileadmin/css/style.css
  config.doctype = xhtml_trans
  10 = USER

#false!
#10.userFunct = tx_templavoila_pil->main_page

#correct!!
  10.userFunc = tx_templavoila_pi1->main_page
}

Now the preview looks great. What a relief. Trying to do the same thing as demonstrated in "Praxiswissenschaft" for the left-hand menu, but for the breadcrumb-menu and time-dependent greeting, I went through the following steps. Note - this did not lead to success.

1) Under "Web", click on "TemplaVoila"
2) Click on the link to the saved Template Map under "Storage Folder"
3) Click on "Update Mapping" and then "Modify DS/TO" (Datastructure / Template Object); in the popup, click "OK"
4) In the "Enter a field name" input, enter (for the time-dependent greeting "field_greeting" and for the breadcrumb-menu "field_menu_breadcrumb")
5) Select "Element" from the dropdown, enter the title "Greeting" (or "Clickpath"), and for "Element Preset" the type "Typoscript Object Path".  Click "Add".
6) Now click "Map". Choose the div tag with the id "meta". It should be of type "INNER" (replacing only the content between the div tags, not the div tags themselves). Click "SET" and then "SAVE".

Now the Typoscript element "lib.field_greeting" and "lib.field_menu_breadcrumb" are available for coniguration with TypoScript in the Template for the TemplaVoila rootpage. I coded it assuming that I could use the same TypoScript I used in the template for the main (non TemplaVoila) root site. This, however, did not work. It didn't BREAK anything, but it didn't render anything, either, except for the "greeting" text:

#create breadcrumb menu
lib.field_greeting = TEXT
lib.field_greeting {
  value = You are here:&nbsp;
  lang.de = Sie sind hier:&nbsp;
}

lib.field_menu_breadcrumb = HMENU
lib.field_menu_breadcrumb {
  special = rootline
  special.range = 2|-1
         
  1 = TMENU
  1 {
    NO = 1
    NO.linkWrap = |&nbsp;&raquo;&nbsp; |*| |
  }
}

Because there is currently no internet access for me to be able to google at this time, I'm going to move on to "Zukunftsichere Typo3-Extensions mit Extbase und Fluid" ("Reliable Typo3 extensions with Extbase and Fluid"), by @Jochen Rau and @Sebastian Kurfürst. I ordered the second edition for my Kindle, but it looks like it went and gave me the first, from 2010. One of the first problems is that the book is unaware of the existence of Typo3 v6. I am annoyed. Life at sea Learning programming can be so inconvenient sometimes most of the time.

Thursday, November 28, 2013

Day 12: kiss my backend

The day of extensions:

Today I spent the first half of the day trying to make the mm_forum not suck, the front-end module suck less, and to extend the functionality of my self-built "Snowboard Teacher" extension. I used only online documentation, and now I am going to share my wisdom with you.

I discovered that with the front-end login extension ("felogin"), the extra sub-page "Login Status", which serves as a target for redirection after a successful login or failed login, did not only NOT work in a sensible way, but was also pretty much unecessary.

Clicking on the "Members Only" page and selecting the "List" module, you can click on the page content for the login form. There, under the "Plugin" tab, there is a subtab for messages. Why create extra pages and redirect to these pages after successful login, failed login, logout, etc., when you can just click on the "Messages" subtab of "Plugin" and write these messages in text? There are "Header" and "Text" fields for "Welcome", "Login Success", "Login Error", "Status", "Logout" and even "Forgot Password".

I entered values for these, deleted the "Login Status" subpage, and tried out the login anew. It works intuitively, unlike the previous workflow of redirecting to pages after these different events. Additionally, you can set up the same thing for the English-language version of the same page-content. Everything is in ONE place, on ONE page, and flows very logically. For this particular use-case, I can highly recommend using the "Messages" subtab of the Login plugin rather than setting up seperate pages for redirect.

I then edited the Login Form template, "felogin_template.html" in "user_uploads", so that it was a bit more orderly and not so... ugly. You can set which template is going to be used for the login formular from the "List" module by clicking on the page content, then the tab "Plugin", and then the subtab "General". Something I found out while editing the template file is that if you edit it directly, after saving, you need to re-select this template from the "General" tab before clearing the cache and refreshing the frontend. Whyever.

The second thing I worked on today was the missing moderator section of the mm_forum. The online documentation for it under http://typo3.org/extension-manuals/mm_forum isn't that great, but it gave me enough insight to figure out how to set this up. Namely, you need to set up either another page (as a sub-page of "Forum") or set a new content area in the "Forum" page itself.

In the content area, select as content type "Plugin". Then as plugin type, select "mm_forum::Forum". After this selection, you will be presented with a dropdown of what to display on this page. Pick "List post queue". If you've done this on the same page as the forum, as I did, and log on as a user with moderation rights (and the forum is set up to have comments moderated before they are published), you will now see an administrative area for moderators ABOVE the forum. This is kind of busy-looking, so I think that I will set up the admin area on its own page instead.

Something else I discovered is that the reason no users showed up in the "mm_forum" module in the "Install" / "User Administration" area is that users will only do so if they are marked as "ForumUser". It doesn't matter if they are also marked as "ForumMod" or "ForumAdmin"! Once you do this, they appear in the "User Administration" area of the forum and can be edited from there.

mm_forum offers several functionalities that apparently must all be set up in a similar way to what I just described: as a mm_forum plugin content area, either on its own site (a sub-site of "Forum"), or on the "Forum" site itself. I'm going to use this knowledge to try and set up all the functionalities as a way to practice.

The final thing I did (with the first half of the day) was to try to extend my self-made "Snowboard teacher" extension. I added a new property to the teacher model in the extension builder, changed the template for listing them out, and took a while to figure out that after saving all these changes, I needed to deactivate (not remove!) and reactivate the extenstion with the "Extension Manager".

Four hours later... 

Four insanity-inducing hours of trying to set up a user registration form for the mm_forum. Here's what I did right and wrong. So, so wrong:

First: you need to set up a new page for forum user registration. Hide it from the menu. Add the content type "Plugin" and then under the "Plugin" tab, give it a "mm_forum" type plugin. After saving this, you can choose what's to be shown on the page: "mm_forum::User Registration". That was the easy part. The hard part is remembering to set up an extension template for this page, "edit the whole template", and in the "includes" tab, to include the following styles in the following order (otherwise, you will get only a page with a title and nothing else):

mm_forum Javascript: Prototyp
mm_forum
mm_forum Stylesheets
Page browser

I had a huge problem with how to set up a link to the forum user registration from the forum logon page (for non-logged in users). I looked around the backend for a LONG time, thinking (illogically?) that this could be configured within the mm_forum module, just as it's possible to configure whether the "forgot password" and "change password" links show up in the forum login form. No such luck.

Another problem is that in the root template, thanks to the tutorial, I've overwritten the default functionality of page headers so that they can no longer display links through their configuration mask. I finally decided just to add a new type of page content underneath the forum login formular: plain old text. In the Rich Text Editor, I simply wrote "Register for the forum", highlighted it, and made it a link to the forum user registration page within the editor itself.

Problem solved. Next problem: in the forum user registration form, there's a whole bunch of labels, but no Captcha (which I specified should be shown), and NO TEXT FIELDS next to the labels! I searched for hours why this could be and eventually just went into the template and deleted 2 marks surrounding the input fields - ###DEFUSERFIELDS###. After deleting these marks, the input fields showed up and I could fill out the form and submit it. It takes forever to validate, but at least it works. I can't believe I spent the whole second half of the day on this, but now I know the backend pretty damn well, at least.

Quick update: the validation email that arrives after having filled out the forum user registration form has only the following text:

Hallo,
vielen Dank für deine Anmeldung auf

Wow - GREAT. Looks like I'll be working on this on Monday, too.

Kiss my backend, Typo3.

Wednesday, November 27, 2013

Day 11: Extensions galore

Today I worked throught the setup and configuration of two popular Typo3 extensions: Piwik, for statistical analysis of website traffic, and mm_forum, for integrating user forums within the Typo3 project site. I also created my own, first (very simple) extension - a frontend plugin for displaying data from a database - with Extension Builder and Fluid.

Piwik is pretty trivial to install. In the Extension Manager under "Get Extensions", type in "Piwik" and install both "piwik" and "piwikintegration". After restarting the backend, you'll see under "Web" a new module: "Pi (Statistics)". In order to use it, however, you have to do a little configuration. Don't worry - this isn't as bad as the News module.

Click on the root page and on "Template" under "Web". Select "edit the whole template" and then in the tab "Includes", from the box "Available Items", select "Piwik Integration (piwikintegration)" and save. Now you can click on the new "Pi (Statistics)" module and click on any page to see a whole BUNCH of possible data on who, how, when, from where, and why (just kidding) users have visited that page. At first it should be empty - you have to log off as the backend administrator and then surf around as some anonymous user on the front-end in order to generate some data.

The available information is pretty overwhelming: each top-level tab (Dashboard, Visitors, Actions, Reference, Goals) has a plethora of sub-tabs. The "Dashboard" is also pretty busy, with a Wordpress style collection of "widgets" that you can organise yourself.

There are two things I'd like to explore further in Piwik that go beyond the scope of the tutorial: which metrics are valuable, and how? Also, how could you simulate high traffic in order to explore meaningful theses about website visits?

The second extension I got to play around with today, mm_forum, did not offer me the relative satisfaction I had after installing Piwik. After finishing this part of the tutorial, I was left with a lot of WTF moments about the functionality and design. But first things first:

To prepare for mm_forum, you have to create a new system folder somewhere in the page-tree - let's call it "ForumData". If you need a refresher on how to do that, here it is: right-click on the "Typo3" logo at the top of the page-tree. Select "new" from the context menu and then, in the right-hand side mask, select the location where this new folder should appear. The location of the "ForumData" folder is unimportant, so I put it at the same level as the "User" folder. The mask that appears now is where you can enter the title of the new folder. Save.

Now, click on the "User" folder we created a few days ago. Click under "Web" on the "List" module. Here you should create three new user groups specifically for the forum: "ForumAdmin", "ForumUser", and "ForumMod". Save.

Finally, click on the "mm_forum" module under "Web" in order to configure it. The "assistant" will ask you to choose a data storage page - choose the "ForumData" folder - and a User storage page - choose our "User" folder. Now you'll be prompted to select a user group for "default" and "admin": choose "ForumUser" and "ForumAdmin", respectively. You'll be presented with yet another page with lots of tabs and a dropdown in the upper-right hand corner. In the dropdown are choices like "Install" (that's where we are right now), "Board Administration", "User Administration", "Templates", "Tools", "Import data", "Statistics", and "User ranks".

In the "Install" mask we can setup the configuration for user, forum, private messaging, search, file-paths, contact, and cron jobs. The "Board Administration" mask is where we set up forum categories and their message boards. Both category and message board can be configured separately, but a message board will inherit the configuration from its category by default.

For both category and message board you can enter a title, the order in which entries should appear, read-access, write-access and moderation-access. For these latter three, you select user groups - this is where the "ForumMod" user group comes into play. And does not quite work or rather, works so well, that no forum comments can *ever* be approved. Even by moderators.

In order for the forum to show up in your site, you now need to create a sub-page, "Forum", under the "Members Only" (login-form protected) page. Click on the "Page" module under "Web" in order to display the content area. Add a new content area to the "main" section and in the tabs that show up where you can pick out what type of content it should be, click on the "Plugin" tab. Select "mm_forum::Forum".

Click again on "Page" under "Web" and click on "Forum" in the page-tree. Click on the "edit" symbol for the new content. Under the "Plugin" tab, there's a section called "Plugin Options" with a tab (why another tab?) called "Forum Options" with a selection of "What to display". Select "Message Board" and save. To change the styles, click on the "Template" module under "Web", click on the "Includes" tab, and then from "Available Items" select "mm_forum Javascript Prototype", "mm_forum", "mm_forum Stylesheets" and "Page Browser" - in that order. Save.

NOW you will see on the front-end any forums you may have set up in the "mm_forum" module under "Board Administration". Playing around with the forum made a few things clear to me immediately:

I can't figure out how, if comment moderation is activated, the moderater is supposed to approve comments. I set up a user called "mod", categorised them under the "ForumMod" group, and set them up with a real email address (mine). In the "mm_forum" module under "Board Administration" I set up one of the categories to have "Moderation Access" for the "ForumMod" user group. In the front-end, when I'm logged on as a normal user, I can make forum entries and am informed that the comment is awaiting activation by moderation.

The thing is, though, that in NONE of the many places where I might, as moderator, theoretically be able to approve comments, is there a list of comments to approve. Notifications are not sent to the moderator's email (mine) either. Neither in the "mm_forum" module, the page module nor the list module for "Forum" is this a possiblity. Logged on to the front end as moderator also shows nothing different from what the normal user sees.

Another problem is that the styles for the forum suck. Trying to access the forum without having logged in does not prompt you to log in. The information provided by "Praxiswissenschaft" that the mm_forum documentation is available for download under the Extension Manager is not really true, so I'm going to have to devise a plan to fix all the stuff that's bugging me about my new forum.

But not today: the next chapter of "Praxiswissenschaft" is allll about creating your own extensions, and that's what I'm really excited about! I'll spend the rest of the day on that - tomorrow on optimising the forum - and writing about creating your own extensions with Extbase and Fluid, which is pretty cool.

Tuesday, November 26, 2013

Day 10: News with the tt_news extension, more language problems

Today we're going to experience the magic of tt_news: the Typo3 extension for adding a news module to your site with minimal fuss.

Start unter "Admin Tools" / "Extension Manager". From the dropdown on the upper left-hand side, pick "Get Extensions". Type in the search field "tt_news" and click on "Go". There are a lot of extentions with this as part of their name. At the top of the list, however, is the right extension - you can verify this by looking at the column called "key". The "key" of an extension is that extensions unique name.

If you click on the little down-pointing arrow next to "tt_news", you'll get a loooong list of all the versions of tt_news, ever, and their status. Perhaps you will be as astonished as I was to see that the latest "stable" version is from early 2005: "News 2.0.6". The latest of many "beta" versions is version 3.5.1, from late 2013. I picked this one to "import and install". (To import and install, click on the left-pointing arrow under the column "Actions").

After downloading the extension, log off the backend and then log back on. You'll see now on the left-hand side under the "Web" category, a new module "News Admin". Additionally, under "Admin Tools" / "Extension Manager" / "Manage Extensions", you'll see that our list of available extensions has been supplemented with the "News" module. If you click on it, you can configure it. In the tutorial for "Praxiswissenschaft Typo3", however, the default configurations are used.

Now comes the hard fun part. Setting up an actual news site in Typo3 requires a lot of really specific steps. However, it only takes about 10 minutes, and compared to programming a news module from scratch (which I've actually had to do way too many times), the Typo3 news module is actually totally awesome. Here are the steps for setting up a site to display a list of news headers with a short excerpt of text, with a link to another site where one can read the entire article. On the page with the entire article, there's a link to go back to the list of all news.

So, pick the page from the page-tree where we want the news list. I'm going to call mine "Current". Click on the "Web" / "Page" icon on the left-hand side. You'll see the template where you can add new content records to the page. In the "main" section, click on the icon for "add a new record". Now under the tab "Plugins", pick "General Plugin". The page will ask you if you want to reload - yeah, sure, why not.

Now under the tab called "General" you can give the news-page a header. I used "Today". In the tab "Plugin", there's a dropdown labeled "Selected Plugin". Pick "News" out of this dropdown. Save! The "Plugin" tab that's now available has several sub-tabs: "General Settings", "Templates", "Category Settings", and "Other Settings". Under "General Settings" there's a dropdown labeled "What to display". Pick "Standard list view (LIST)".

Now, on the left-hand side under "Web", click on the "List" module. Click on the page "Actual" in the page tree. At the upper left-hand side of the mask, click on the plus, "add a new record". A tree-type list appears where you can pick what kind of content you want to add. Under the header "News", you can pick either "news" or "news category". Pick "news".

This is where can enter actual news content: title, text, etc. Make sure to unclick the checkbox "hide" so that our content will be visible. Save your changes.

Now we need to make a static template for the content. Unter "Web", click on "Template" and the root page. Click on "edit whole template record". You'll see some tabs: pick the tab called "Includes". On the lower right-hand side there's an area called "Available Items" where you can make selections. Select "News Settings (tt_news)" and save.

If you look at the frontend now, you'll just see an error (or in my case, nothing). That's because you still have to go through about 8 more steps to get this thing up and running. In order to see the whole news article that we would theoretically pick from the as-yet not existing news list, we need to create a sub-page under the page called "Actual". Right-click on the "Actual" page and select "Page-actions" -> "add".

In the mask, check "hide in menu", pick from the "Type" dropdpown the type "Standard", and save. Click on "Web" / "Page" now and in the content template in the main content area, click on the plus icon to "add a new record".  Click on the "Plugins" tab. Select the "News" plugin. From the mask that now appears, pick the "Plugin" tab (again - I know that it's gotten confusing) and then the tab "General Settings". There in the dropdown "What to display" pick "Detail view - SINGLE". Remeber to save, otherwise you'll have to start all over again.

Now click on "Actual" again, and "Web" / "Page". In the main content area, click on the edit symbol (the pencil) for the news content item. Click the "Plugin" Tab and then on the "Other Settings" tab. Click on the "folder" symbol next to the label called "PageId for single news display" in order to pick the page we just created for the single-news item. Save!

Think we're done yet?  WRONG. Do the whole song-and-dance for the single-news item subpage under "Actual". For whatever reason, you have to specify in the single-news item page under "PageId for single news display" that the page it should refer to is itself (eye-roll). Additionally, click on the folder symbol near the label "PageId to return to" in order to pick the parent page, "Actual" in oder to generate a useful link that will allow us to return from the single-news item detail to the news list.

NOW we have a usable news module for our frontend whose content can now be easily maintained by editors who lack the insane desire to mess around with the backend. I know that the setup seems... awkward, but it would have taken longer (and been more tedious) to program the same thing from scratch. Typo3 takes care of the things we've done a hundred times before so that we have more time to program new and challenging functionality, refactor and explore! The day's only half done and, again, I've learned something quite useful.

It was really bugging me that the images for the "trailer" had disappeared on introduction of an English-language version of all pages. The disappearance of the static-right hand content (also only from the English-language pages) was bugging me too, so after a few minutes of googling, I found 2 useless suggestions and 1 good one. I'll spare you the former but share with you the secret of my success.

Namely, the root (and other helper-pages like "static-right hand") from which subpages are supposed to inherit, need to have an English-language version too. Copy the content of helper-pages, if there is any, and as far as inherited images go, you need to click on the "Resources" tab of the English-version of the page.

There you'll see a pale version of the image that appears under the "Resources" tab of the original-language version of the page. To the right of this image there's a barely discernable icon called "localize". Click on this, wait a minute, clear the cache and refresh the front-page. Voila... now the site behaves as it should.

This seems to be more of a feature than a bug, but it would have been nice for the "Praxiswissen Typo3" tutorial - WHICH USES A MULTI-LANGUAGE SITE AS ITS EXAMPLE - to have mentioned this tiny little detail.

Next up: configure an indexed-search without being deterred by the trauma left over from setting up the "simple" search form!

Monday, November 25, 2013

Day 9: Multilinguality in Typo3 sites (stupid flags...)

Day 9, chapter 9: let's dive right in, shall we?

Today I'm working through the rest of chapter 9 of "Praxiswissen Typo3", which involves providing various text-elements of the project site in both English and German. In order to do this, all "override" properties (which can be seen in the TypoScript Object Browser) need to be removed, and all properties that have access to the method "lang" need to be so set: "lang.de".

Some properties, such as "badMess" (Javascript error message) and "wrap", do not have access to the "lang" method, so need to be set explicitly in a conditional after all "page" properties have been set. Here is how the search form looks after transformation:

tt_content.search.30 {
#js error if user does not fill out required field (implemented below in dataArray.10)
  badMess = Bitte füllen Sie alle erforderlichen Felder aus.

#text input: required, name ="sword", size=15, maxsize=30, label = "Ihre Suche:"
  dataArray.10 {
    type = *sword=input, 15, 30

#previously: value.override = Suchwort
    value.override.lang.de = Suchwort

#previously: label.override = Ihre Suche:
    label.override.lang.de = Ihre Suche:
  }

...

#dynamically generated graphical submit button
  image = IMAGE
  image.file = GIFBUILDER
  image.file {
    XY = [10.w]+10,20
    backColor = #76001B
   
    10 = TEXT
    10 {
#previously: text = Suche
      text.lang.de = Suche

      fontFile = fileadmin/fonts/Ubuntu-C.ttf
      fontColor = white
      fontSize = 14
      #niceText = 1
      offset = 5,15
    }
  }
}

We have to explicitly set conditionals for the properties "badMess" (and "wrap"). This block of code comes after all page properties have been set:

page {
...
}

#Multilinguality
#if the GP (GET Parameter) is 1 (english), then set the system language id to 1,
#the configuration language to English,
#the local to G.B.

[globalVar = GP:L=1]
  config.sys_language_uid = 1
  config.language = en
  config.locale_all = gb_UK

#english translations for error message and wrap go here

#for our search field overhead on the right-hand side
  page.10.marks.SUCHE.badMess = Please fill in the following fields:
  page.10.marks.DATUM.10.wrap = |, today is the&nbsp;

#for our search form in a page
  tt_content.search.30.badMess = Please fill in the following fields:
  tt_content.search.30.image.file.10.text = Search
[global]

Is this all making sense? I find it logical TODAY, but it's all built on 5 days of non-stop intensive TypoScript-learning.

The next step is to replace the language menu, whose current values are links of the text "English" and "German", with two small images of flags (of England and Germany, of course). The mark for the language menu, "###SPRACHE###", needs to be initialised as an HMENU object whose first and only level is graphical (i.e., GMENU).

Note here that there is yet another type of menu defined by "special": we've seen "special = directory" for the classical menu and "special = rootline" for an inline menu, but now we have "special = language", for a language dependent menu.

#language menu    
      SPRACHE = HMENU
      SPRACHE {
        special = language
        special.value = 0,1
       
#normal status of first (and only) level of the language menu - it's graphical        
        1 = GMENU
        1.NO {
          XY = [10.w]+2, [10.h]+2
          backColor = white

#our language menu is made up of two images:
#the German and the English flag for German and English (duh)        
          10 = IMAGE
          10.file = fileadmin/flags/de.gif || fileadmin/flags/gb.gif
          10.offset = 2,2
        }
       
#active status, language menu      
        1.ACT = 1
       
#take properties from the normal status of the language menu
        1.ACT < .1.NO

#override the effect so that the active (currently selected) language shows is greyed out
        1.ACT.20 = EFFECT
        1.ACT.20.value = gray | gamma=1.5
      }

This sort of worked. On the homepage, the correct flag was greyed out depending on what language I had selected. On all other pages, however, only when "German" was selected was a flag greyed out at all (it was the correct one). The flag for "English" stayed bright an colorful on all pages, except the homepage, after being selected. WTF?

I decided to experiment and to create English versions for the other pages - at least the menu title should be translated, by my logic. This is done by clicking on "Page" under the "Web" module on the left-hand side. On the upper left-hand side of the mask that appears, there is a drop-down with the choices "Columns", "Languages" and "Quick-edit". Select "Languages". Another dropdown labelled "make a new translation of this page" allows you to select one of the languages that has been set for the site-root (represented in the page-tree with the Typo3 icon). Select "English".

You are now shown a page with the title "Create new Alternative Page Language". Enter a title in the textfield "Page Title" (obviously). Make sure that the visibility is enabled under the tab "Access" and then save your changes.

NOW, when you click on the page in the frontend of which you just created an English "translation", and pick the English flag icon - IT STAYS GREY! Logically, in order for the selected page to represent the selected language, you have to actually have a translation of that page in the selected language.

One problem with this is that now the header images are gone. (Cries). Do I have to set those up for the English-translation pages too? When I switch the language via flag to "German", yep... the images are still there. I think I'm going to work on setting up user-protected areas now: pages whose content is protected with a login form and a list of permitted users. Also: dynamically-generated print-versions of every page, with just a few lines of TypoScript in the root template.

Four hours later...

Stay tuned for tomorrow's Typo3 excitement, as I attempt to install the tt_news plugin, whose last stable, non-beta version was uploaded in 2005!

Thursday, November 21, 2013

Day 8: the search-form from hell, static-dynamic content, a customised backend

Part I: the Search-Form from Hell

I spent the first half of the day today trying to figure out why my search-form wouldn't work. Most of that time was spent wrong because I was searching for "indexed search function", whereas the functionality referred to in "Praxiswissenschaft" happens to be the normal, non-indexed one.  In the end, I did 3 things that possibly caused the form to eventually work:

1) I deinstalled the extension "indexed_search" that I had installed yesterday in the belief that it was needed.

2) in the file typo3_src/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php I changed line 732 of code from this:

$content .= $hookObj->cObjGetSingleExt($name, $conf, $TSkey, $this);

to this:

$content .= $hookObj->cObjGetSingleExt($name, (array) $conf, $TSkey, $this);

This change was based on a tip that I found via google that seems to address the error message I kept getting: that a second argument was expecting an array and receiving something else.

This change caused the page to go from displaying an exception error to displaying the page with the marks for the searchform, "###SUCHE###", instead of the actual search form itself.

3) Finally, the tip that Meyer's book gives, and also to be found in several pages via google, is to deinstall the "form" extension. When I did that yesterday, in place of an exception I got an internal server error instead, which is actually worse. Today was the same thing. Only after lunch, by following steps 1 and 2 again, and then (again) deinstalling the "form" extension, did the search form finally work.

Logically, this should have happened yesterday as I had followed steps one and two, before installing the indexed search. The ways of Typo3 are shrouded in mystery!

Now I am free to continue the "content" chapter of "Praxiswissenschaft".

I found out a way to supplement the root template TypoScript without literally typing it in the text area: under "Template" for the root page, select "TypoScript object browser" instead of "Info/Modify". Click on the TypoScript object you'd like to modify and a form comes up called "Edit object/property value". Enter the object property in the text field and click up "update". In the root template, the correct code for this property attribution can now to be seen. 

Using this method to change properties is a good way to avoid the typos and mistakes of typing code in by hand; however, it does not have the benefit of code-organisation that can be attained by doing the same thing manually. Additionally, clearing and reseting values in this way makes a mess of the TypoScript in the template textarea, much like creating HTML markup with a WYSIWYG editor. I'm going to decide for clean code and write my TypoScript by hand - I need the practice, anyway.

Part II: Static-Dynamic Content

In order to create a content area that appears on every page (for example, news items on the right-hand side of each page) whose content is dynamic, a mark within the template is necessary, but does not alone suffice. It's also necessary to, once again, set up a helper-page, just below the root page in the site structure. This new helper pages's properties include being of type "shortcut", redirecting to the homepage if called directly in the browser, having enabled visibility, and yet be hidden to the menu. This last property can be achieved by selecting the "Access" tab within the "Page" section and then checking the box "In Menus - hide". Finally, in order to bind this helper page's content into the template that is used by all pages, the following code needs to be implemented:

#make "RECHTS" (right-hand side) marker a content object array
      RECHTS = COA

#read out the content of right-hand column of the current page into the RECHTS marker in all positions
      RECHTS.10 < styles.content.getRight
      RECHTS.20 < styles.content.getRight

#the content of the right-hand-side column should, however, only be read from a list of pages whose page IDs are explicitly set below
      RECHTS.20.select.pidInList = 17

It's additionally suggested that in order to prevent the contents of this page from being cached, which would prevent new content from appearing without first manually emptying the cache, the object type COA_INT instead of COA can be used. 

Part III: customising your backend (ha!)

In order to create a customized backend layout to make content management for editors easier, click on the "List" module under "Web", and then click on the "root" page. In the upper left-hand corner to the new window, click "create new record". A list of possible types appears; select under "System records" the type "Backend layout". There, enter a name for the customised template and then click on the image next to the text field under the label "configure". This will open up a new window where columns and rows for a table can be defined: each cell of this table needs a name and a unique column number.

After saving this configuration in the new window AND in the opening window (otherwise, the work is lost - I had to find this out on my own), click on the root page and select "edit" from the context menu. Under the tab "Appearance", it's now possible to select the new template as "Backend Layout (this page only)" and "Backend Layout (subpages of this page)". Remeber to save! Clicking on the "Page" module under "Web" and selecting the root page will now show the new template for entering content, instead of the the default one. In this way, it's possible to customise content-entry forms and make them more user-friendly for editors.

Prologue

Today I got through one chapter of "Praxiswissen", with one major problem (the non-functionting, error-causing search form) and two minor ones: getting the dynamic right-hand area of every page to show the same content (I had initially put the new right-hand content area in the homepage instead of in the root document) and not being able to FIND the area for adding a customised backend layout (the instructions in the book skipped the step of getting to the "System records" list of choices). I was able to solve them with a little experimentation and a lot of googling. 

The seas have calmed, wind and weather are good, routine has entered the daily course of being on board the Hackership and I am actually learning somthing practical.

The first two weeks are over, four to go. Will I have time to immerse myself in test-driven development with PHPUnit? Will I be able to figure out how to configure my Jenkins CI server to run these tests as jobs? I think I'm going to have to invest in more resources (i.e. e-books). Without "Praxiswissen" my ship would have, by now, floundered on the rocks of bad documentation with no help in sight. 

Who's sick of the seagoing metaphores already? 
Too bad!


Wednesday, November 20, 2013

Day 7: ImageMagick, Navigation, lots and lots of TypoScript

Day 7: smooth sailing with "Praxiswissen Typo3"

It was really bugging me today that the dynamic graphical part of the project wasn't working. I rechecked the code and found, first of all, that some of my code was nested falsely.  After fixing that, it still didn't work, so I read through the chapter again and figured that my problems must be with ImageMagick: namely, the mask underneath the image, "nicetext", and image inheritance from the root page as defined by TypoScript IMAGE object properties were not working.

I checked out which version of ImageMagick is installed on my computer by typing on the command line:

identify -version

According to the output, I have ImageMagick version 6.7.7-10.  After some more googling (for "ImageMagick nicetext") I found the perfect solution. Pretty much, ImageMagick will only function on the root server with a certain Typo3 configuration:

[GFX][gdlib] = 1
[GFX][gdlib_png] = 1
[GFX][im] = 1
[GFX][im_version_5] = im6
[GFX][im_negate_mask] = 1
[GFX][im_imvMaskState] = 1
[GFX][im_no_effects] = 1
[GFX][im_v5effects] = 0
[GFX][im_mask_temp_ext_gif] = 1

Especially important is the configuration "[GFX][gdlib_png] = 1". I called up the Typo3 install tool in the browser, logged on, and under "All Configuration" searched for these values to see how they were set. Lo and behold, in my configuration, [GFX][gdlib_png] was set to 0.  I changed this and refreshed my Typo3 project and voilá - it is now working as it should.

On to creating the navigation menus, dynamically of course!

Something I've discovered today is that, in order for the menus to be shown, the "helper sites" I created yesterday need to be set to VISIBLE, not, as I interpreted from the tutorial, have the visibility deactivated.

In order to create my first menu - the single-layer, overhead text menu - I had to 1) specify an object of type HMENU, 2) set the properties of this new menu object so that it is a "directory" or classical menu, 3) set the root of this "directory" to the page ID of the root page and 4) specify that the first (and only) layer of the menu is a text menu with "normal" state activated.  The TypoScript code to do this is as follows, and is inserted within the "marks" section of the TypoScript:

marks {
...

#upper text-menu
  MENU_OBEN = HMENU
  MENU_OBEN {
         
#directory, or classic menu
    special = directory
       
#page-id of the menu root      
    special.value = 2

#this menu has only one level, which is a text-menu, with normal (NO) state activated    
    1 = TMENU
    1 {
      NO = 1
      NO.linkWrap = |
    }
  }
...
}

The pipe symbol | stands for dynamic content that can be, if desired, "wrapped" within html code, such as bold tags, or an empty space. To seperate individual links with an empty space, write in the place of "NO.linkWrap = |" the following line of code:

NO.linkWrap = &nbsp;|

For bolded content, write:

NO.linkWrap = <b>|</b>

In order, however, to use a stylesheet on the generated menu links, use the property "ATagParams" on the "normal" property of the textmenu, for example:

NO.ATagParams = class="left_white"

Building up the left-hand side graphical menu requires a bit more code in order to dynamically generate the text as images and to have a normal, rollover, and active state for each link. My TypoScript works for the normal and active states of the generated links, but rolling over the links with the mouse in the browser has no effect. When I look at the HTML source code, I see that on "onMouseover", the same image is being called as on "onMouseout". After a lot of googling, I'm not any further. Testing in Firefox gives the same results, so it's not necessarily related to the browser.

Here's the code for generating a graphical menu. It differs only slightly from the code for a text menu, in that the object GMENU (graphical menu) is used in place of TMENU (text menu) and that within the "1" section, there are also definitions for the rollover (RO) and active (ACT) states of the links.  This menu, too, is placed within the "marks" code section.

marks {
...
  MENU_LINKS = HMENU
  MENU_LINKS {
    special = directory
    special.value = 3  
    1 = GMENU  
    1 {
#describe normal state        
      NO = 1
...
#define rollover (RO) state
#copy normal (NO) properties
      RO < .NO
#redfine the properties for rollover only where they differ from the normal (NO)
...

#define active (ACT) state
      ACT < .RO
    }
  }
...
}

On to developing a second level for the graphical navigation. This requires the setting of a second GMENU and its properties, along with the descriptions for its normal (NO), rollover (RO) and active (ACT) states. It's possible to do this in TypoScript without redundant typing with the following line of code

2 < .1

which means: "2", or the second level, is also a GMENU object whose properties are exactly the same as the "1" GMENU object.  We are then free to overwrite only the properties that differ from those of GMENU object "1":

2.NO {
  XY = 230,25
       
#white background
  5 = BOX
  5 {
    color = white
    dimensions = 10,0,200,25
   }
         
#change text styles        
   10 {
#set text styles (case) back to nothing
     text.case >
     fontSize = 12
     offset = 20,16
   }
}
       
#rollover and active state
2.RO < .2.NO
2.RO.10.fontColor = #a90329
       
#active (ACT) state for level two in the same as the rollover (RO) state      
2.ACT < .2.RO
     
       
For setting up a breadcrumb trail, the process is similar, since it is also a type of menu. In order to differentiate between the breadcrumb-style and classic-style of menus, however, we need to set the "special" property to "rootline" instead of "directory". Here's the basic code which, you can see, is similar to the syntax for the overhead text-menu:

KLICKPFAD = HMENU
KLICKPFAD {
  special = rootline
  1 = TMENU
  1 {
    NO = 1
...
  }
}

Blend the VISIBLE helper-pages out of the breadcrumb trail with a line of TypoScript which specifies from which level the page navigation should begin and where it should end:

special.range = 2|-1

Start at level 2, since the root helper page is at level 0 and the two helper pages for template inheritance can be found at level 1. "-1" ("forever") indicates that all remaining levels can be shown.

Changing the object type of "KLICKPFAD" from HMENU to COA (content object array) makes it additionally possible to set up a sequential list of multiple object types (like TEXT, IMAGE and, yes, HMENU) and their properties, instead of being limited to only the properties assignable to HMENU. This lends an enormous flexibility to scripting the display of a Typo3 site. Here's an example of that.

#create breadcrumb menu as content object array
KLICKPFAD = COA
KLICKPFAD {

#in first position, we want to see some text
  10 = TEXT
  10.value = You are here:&nbsp;
       
#in second position, we want a text menu
  20 = HMENU
  20 {
    special = rootline
    special.range = 2|-1
         
    1 = TMENU
    1 {
      NO = 1
...
    }
  }
}

These blog entries are getting longer (and more professional from a programming standpoint. Less so, from a literary one). I still have a few hours to go on with the tutorial, but I will continue with that tomorrow: chapter 8 of @Robert Meyer's "Praxiswissen Typo3" - "Content".