Elsewhere

Johannes Schauer: mapbender - maps for long-distance travels

Planet Debian - Thu, 03/04/2014 - 12:47

Back in 2007 I stumbled over the "Plus Fours Routefinder", an invention of the 1920's. It's worn on the wrist and allows the user to scroll through a map of the route they planned to take, rolled up on little wooden rollers.

At that point I thought: that's awesome for long trips where you either dont want to take electronics with you or where you are without any electricity for a long time. And creating such rollable custom maps of your route automatically using openstreetmap data should be a breeze! Nevertheless it seems nobody picked up the idea.

Years passed and in a few weeks I'll go on a biking trip along the Weser, a river in nothern Germany. For my last multi-day trip (which was through the Odenwald, an area in southern Germany) I printed a big map from openstreetmap data which contained the whole route. Openstreetmap data is fantastic for this because in contrast to commercial maps it doesnt only allow you to just print the area you need but also allows you to highlight your planned route and objects you would probably not find in most commercial maps like for example supermarkets to stock up on supplies or bicycle repair shops.

Unfortunately such big maps have the disadvantage that to show everything in the amount of detail that you want along your route, they have to be pretty huge and thus easily become an inconvenience because the local plotter can't handle paper as large as DIN A0 or because it's a pain to repeatedly fold and unfold the whole thing every time you want to look at it. Strong winds are also no fun with a huge sheet of paper in your hands. One solution would be to print DIN A4 sized map regions in the desired scale. But that has the disadvantage that either you find yourself going back and forth between subsequent pages because you happen to be right at the border between two pages or you have to print sufficiently large overlaps, resulting in many duplicate map pieces and more pages of paper than you would like to carry with you.

It was then that I remembered the "Plus Fours Routefinder" concept. Given a predefined route it only shows what's important to you: all things close to the route you plan to travel along. Since it's a long continuous roll of paper there is no problem with folding because as you travel along the route you unroll one end and roll up the other. And because it's a long continuous map there is also no need for flipping pages or large overlap regions. There is not even the problem of not finding a big enough sheet of paper because multiple DIN A4 sheets can easily be glued together at their ends to form a long roll.

On the left you see the route we want to take: the bicycle route along the Weser river. If I wanted to print that map on a scale that allows me to see objects in sufficient detail along our route, then I would also see objects in Hamburg (upper right corner) in the same amount of detail. Clearly a waste of ink and paper as the route is never even close to Hamburg.

As the first step, a smooth approximation of the route has to be found. It seems that the best way to do that is to calculate a B-Spline curve approximating the input data with a given smoothness. On the right you can see the approximated curve with a smoothing value of 6. The curve is sampled into 20 linear segments. I calculated the B-Spline using the FITPACK library to which scipy offers a Python binding.

The next step is to expand each of the line segments into quadrilaterals. The distance between the vertices of the quadrilaterals and the ends of the line segment they belong to is the same along the whole path and obviously has to be big enough such that every point along the route falls into one quadrilateral. In this example, I draw only 20 quadrilaterals for visual clarity. In practice one wants many more for a smoother approximation.

Using a simple transform, each point of the original map and the original path in each quadrilateral is then mapped to a point inside the corresponding "straight" rectangle. Each target rectangle has the height of the line segment it corresponds to. It can be seen that while the large scale curvature of the path is lost in the result, fine details remain perfectly visible. The assumption here is, that while travelling a path several hundred kilometers long, it does not matter that large scale curvature that one is not able to perceive anyways is not preserved.

The transformation is done on a Mercator projection of the map itself as well as the data of the path. Therefore, this method probably doesnt work if you plan to travel to one of the poles.

Currently I transform openstreetmap bitmap data. This is not quite optimal as it leads to text on the map being distorted. It would be just as easy to apply the necessary transformations to raw openstreetmap XML data but unfortunately I didnt find a way to render the resulting transformed map data as a raster image without setting up a database. I would've thought that it would be possible to have a standalone program reading openstreetmap XML and dumping out raster or svg images without a round trip through a database. Furthermore, tilemill, one of the programs that seem to be one of the least hasslesome to set up and produce raster images is stuck in an ITP and the existing packaging attempt fails to produce a non-empty binary package. Since I have no clue about nodejs packaging, I wrote about this to the pkg-javascript-devel list. Maybe I can find a kind soul to help me with it.

The code that produced the images in this post is very crude, unoptimized and kinda messy. If you dont care, then it can be accessed here

Categories: Elsewhere

Code Positive: Sage Pay

Planet Drupal - Thu, 03/04/2014 - 12:20

Sage Pay is one of the world’s most trusted payment solutions providers.

Our brief was to create a platform which could be used to build and maintain a website for each of the countries Sage Pay operates in, supporting existing customers and promoting Sage Pay services in those countries.

Background

Sage Pay has earned a reputation for security and good service. From startups to major brands, fifty thousand business of all sizes relly on Sage Pay to succesfully processes customer payments.

Sage Pay approched Code Positive to re-build the main corporate platform from which all Sage Pay country websites are built and maintained. The objectives were to present fresh new branding and make it possible for Sage Pay customers, partners, and developers to more quickly find solutions and information.  

Code Positive provided consultancy, project planning, project management, development, and on-going support for the project.

Drupal was used to implemented the project, and hosting was provided by Acquia.

Site Highlights Marketing

The Payment Solutions section features visually rich explanations of the advantages of Sage Pay products, step-by-step guides on how to switch to Sage Pay, and information for statups and corporates. Each page has a clear call to action to connect the visitor to the sage Pay sales team.

The Partner and Developer section of the site provides information on becoming a partner, and helps partners and developers find developer resources and information about 3rd party integrations. Similar to the Solutions section, navigation is visually driven and there is a good balance of imagery and content on the pages with strong call to actions in the form of buttons, teasers with icons and customer logos linked to case studies.

Customer and partner case studies highlight how different Sage Pay solutions have solved problems and met the needs of customers and partners - two different audiences for Sage Pay. The case studies grab the attention of the reader with quotes and logos from prominent customers and partners. Case studies are promoted throughout the site with case study carousels and lists of linked logo thumbnails.

Support

The support section makes it quick and easy for Sage Pay’s various audiences to find the help that they need.

It features support articles on various topics, integration guides explaing how Sage Pay products can be used with other applications, online shoppers FAQ for anyone making payments through Sage Pay services, and contact details for 24/7 support services through which clients and partners can get more information.

Also available in the support section are logo downloads that can be added to a website to show it’s using Sage Pay services, a beta testing programme registration, a glossary with definitions of termnology used on the site, and explanations of error codes and their suggested solutions.

One of the most important features of the site is the system monitor which provides up to the moment information on the status of Sage Pay services.

The support section has a search facility, including the option to search specifically in error codes so that integrators can quickly diagnose problems and find solutions.

The Sage Pay forum is hosted externaly on Stack Overflow. which has excellent tools for technical support and a large and active developer community.

Content Strategy

The client’s brief had two almost contradictory requirements for the site’s content strategy:

  1. Flexibility to add a completely different mix of content to each page
  2. Rigidlly defined content fields that would guide staff in entering content

A flexible content system would enable the marketing department to create whatever message was appropriate for each page. Rigid content fields would maintain consistency across the site, and allow content parts to be re-used on other pages, or hidden on mobile devices.

We squared this circle by analyzing the content that would be added to the site and found common repeating patterns, we then implemented each of the patterns as component types that could be added to any page in any order. Options were also added so the client could control the position and styling of each component as it was created.

We met this challenge by analysing the planned site content to find common repeating patterns. We then built a component for each of these patterns, that could be used to add structured content to any page in any order. The components included flexible configuration options that empowered Sage Pay to control the layout, styling and order of the content as it is added to a page.

Most of the components were developed to have a one-to-one relationship with the page they would be added to, and we also provided a few components that could be re-used on multiple pages.

After a few weeks of use, feedback from the client enabled us to refine the user interface of the component system, to provide a system that is flexible, powerful, and easy to use.

Tokens

One of the challenges was to make it easy for Sage Pay to manage and maintain lots of pieces of information, like telephone numbers and prices, across multiple pages.

To solve this problem, we implemented a token system that enable the client to use place holder tokens anywhere in their copy, which are automatically filled in with information before being displayed on the web page.

The client can easily create new tokens as required, and updating the information associated with a token updates the information across the website.

Media Management

The website makes extensive use of images, videos, and downloadable documents as part of it’s marketing and support features.

We used Media module to implement a media management system that enables the client to add media to the site’s asset library, re-use them across multiple pages, and track which pages each asset is used on.

The system also allows the client to update a media asset, such as a new image of a product, and have the site display the new version everywhere it used the old version.

Drupal Contributions Node View Mode

Provides a field that can be used to select a view mode on each node.

Node View Mode The Results

The site has exceeded the client’s expectations for flexibility and ease of use in adding content. Sage Pay’s marketing and support teams are excited about the positive feedback from customers, developers and partners.

Drupal ConsultingDrupal DevelopmentDrupal Maintenance
Categories: Elsewhere

Gerfried Fuchs: 2CELLOS

Planet Debian - Thu, 03/04/2014 - 12:08

A good friend just yesterday sent me a link to a one and a half hour lasting live concert of 2CELLOS. And wow, I was deeply impressed. Terrific! Even Sir Elton John approves. Have to share them with you, too. :)

Enjoy!

P.S.: I sooo love them also for their pun in their second album title, In2ition. :D

/music | permanent link | Comments: 0 | Flattr this

Categories: Elsewhere

Aigars Mahinovs: Wireless photo workflow

Planet Debian - Thu, 03/04/2014 - 11:51

For a while now I've been looking for ways to improve my photo workflow - to simplify and speed up the process. Now I've gotten a new toy to help that along - a Panasonic FlashAir SD card with WiFi connectivity. I was pretty sure that build-in workflows of some more automated solutions would not be a perfect fit for me, so I got this card which has a more manual workflow and a reasonable API, so I could write my own.

Now I am trying to work out my requirements, the user stories if you will.

I see two distinct workflows: live event and travel pictures.

In both cases I want the images to retain the file names, Exif information and timing of the original photos and also have embedded GPS information from the phone synced to the time the photo was taken. And if I take a burst of very similar photos, I want the uploading process to only select and upload the "best" one (trivial heiristic being the file size) with an ability for me to later choose another one to replace it. There would need to be some way of syncing phone and camera time, especially considering that phones usually switch to local time zone when traveling and cameras do not, maybe the original time the photo was taken would need to be changed to local time zone, so that there are no photos that are taken during the day, but have a timestamp of 23:45 GMT.

When I am in Live Event mode I would like the photos that I take to immediately start uploading to an event album that I create (or choose) at the start of the shoot with a preset privacy mode. This assumes that either I am willing to upload via 3G of my phone or that I have access to a stable WiFi network on-site. It might be good if I could upload a scaled down version of the pictures during the event and then later replace the image files with full-size images when the even is over and I am at home in my high-speed network. I probably don't need the full size files on my phone.

When I am in Travel mode, I want to delay photo uploading until I am back at the hotel with its high speed Wifi, but also have an option to share some snapshots immediately over 3G or random cafe Wifi. I am likely to take more photos that there is memory in my phone, so I would like to clear original files from the phone while keeping them in the SD card and in the cloud, but still keeping enough metadata to allow re-uploading an image or choosing another image in a burst.

Now I need to flesh out the technical requirements from the above and write an Android app to implement that. Or maybe start by writing this in Python as a cross-platform command-line/desktop app and only later porting it to Android when all the rought parts are ironed out. This will have an extra benefit of people being able to run the same workflow on a laptop instead of a phone or tablet.

Let's assume that this is written in a pretty flexible way, allowing to plug in backends for different WiFi SD cards, cloud services, plug-in points for things like instant display of the latest photo on the laptop screen in full-screen mode and other custom actions, what else would people love to see in something like this? What other workflow am I completely overlooking?

Categories: Elsewhere

Károly Négyesi: Drupal 8 progress from my / MongoDB perspective: update #26

Planet Drupal - Thu, 03/04/2014 - 06:28

At DrupalDevDays Szeged, skipyT, fgm and myself made tremendous progress with writing the MongoDB drivers. All the override mechanisms work as expected and things in general, work. Most importantly, we have an entity storage backend and a significant percentage of the entity storage query tests pass (it is not expected all ever would pass, for example relationships are not supported). I have also managed to get the "add aggregator feed" test pass (going in ABC order among entities), this hit a snag where a recent rewrite of the testing framework broke overriding services during testing and I am not allowed to fix this so automated testing will require a small core patch. Otherwise we would need to create a mostly empty testing class for every test, this is clearly not desirable. Also at DDD, Ricardo Amaro and Jeremy Thorson have made significant strides in creating a more modern testbot based on Docker, I intend to run an instance at home and see how MongoDB fares with all the tests. I am reasonably confident by the time the beta happens, you will be able to run it solely on MongoDB.

Meanwhile, migration got stalled by an unrelated core issue, it's close to a resolution now. Other core changes broke many migrations but by now we should be back on track and again, I am reasonably sure by beta time the Drupal 6 to Drupal 8 path will be there to test. Will Drupal 7? I hope too but nothing is certain.

Categories: Elsewhere

Andrew Pollock: [life] Day 65: Playgroup, and the foil confetti play date

Planet Debian - Thu, 03/04/2014 - 06:11

Zoe slept pretty well last night. She only woke up briefly at 4am because Cowie had fallen out of bed and she couldn't find her.

Today was the last Playgroup of the term. Megan, her little sister and her Dad came as well to check it out, which was nice, because Zoe then had someone to actively play with in addition to me.

After Playgroup, we went to the adjacent Bulimba Memorial Park with Megan, and then had some lunch at Grill'd. Megan's Dad wanted to do some work on their house while Megan's little sister napped, so I offered to give Megan a play date at our place.

The plan was to watch a movie and chill out. The girls picked Ratatouille and I made a batch of popcorn for them. Unfortunately Megan seemed to be less of a square eyes than Zoe, and she lost interest after a bit, so we stopped watching the movie and moved out to the balcony to do some craft.

Zoe had been wanting to make a crown for Mummy's boss for a while, so we made a couple of crowns with the hot glue gun. I had bought this bag of mixed craft "jewels" and it's probably the best single craft thing I've bought. Zoe loves gluing them onto everything.

After that, Zoe pulled out the bag of coloured foil confetti. If the gems were the best thing I've bought, this would have to be the worst. So far, all it's done is leak in the drawer it's been stored in, and I've been avoiding using it because it was going to be messy.

Today, Zoe wanted to glue it onto the outside of her cardboard box, so I decided to give in and embrace the mess, and boy, did we make a mess.

It probably ended up being the longest bit of cooperative play the girls did. They'd alternate between handing each other a fistful of confetti while I applied globs of glue where directed. Probably about 10 percent of each handful ended up stuck to the rocket, so the balcony looked like quite a mess by the end of it all, but at least it was a dry mess, so I could just vacuum it all up. I suspect I'll be encountering dregs for quite a while, because I doubt it's stuck to the cardboard particularly well.

After that, the girls played indoors for a bit, and watched a bit more of the movie, but Megan seemed to be scared of Anton Ego, so I think that was why it wasn't holding her attention.

The other activity that the girls seemed to thoroughly enjoy was tearing around the living room squealing while they took turns at throwing a grapefruit-sized beach ball at me, and I threw it back at them.

Jason came back to pick up Megan, and I started dinner. Not that long after Megan left, Sarah arrived to watch Zoe for me so I could go visit my cousin in hospital. I had dinner on the table pretty much as soon as she walked in the door, and headed out.

Categories: Elsewhere

Drupal core announcements: This week-ish in Drupal core: April 2, 2014

Planet Drupal - Wed, 02/04/2014 - 23:32
What's new with Drupal 8?

The past three weeks saw some exciting progress on Drupal 8, in part due to the hard work of everyone who went to DrupalDevDays 2014 in Szeged, Hungary. It also saw the release of drupal-8.x-alpha10.

Drupal Developer Days Szeged

DevDays Szeged was a landmark for the Drupal 8 release cycle. Participants marveled at how productive and well-organized the event was, and core maintainers commented they'd never seen such momentum in the RTBC queue. During the week-long sprint, 19 beta blocking issues were fixed (with three more RTBC) and every single missing change record was written. Outside core, sprinters also made significant progress on everything from the Search API module for Drupal 8 to Drupal.org itself. A robot doll, chocolates, bunny ears, stickers, and Drupal-ified Hungarian folk music also made it the event of the year. (Szeged slide show)

Alpha 10 released; Alpha 11 due Apr. 23

Alpha 10 was released on March 19th, just before Drupal Dev Days. Some notable changes include:

... for the full list of changes, see the alpha 10 release notes.

These alphas are provided to give you something more stable to work off of than having to chase HEAD every day.

Where's Drupal 8 at in terms of release?

Core momentum increased again in March, with a new all-time record of 51 criticals fixed over the month. In fact, we've nearly recovered to the level of known technical debt we had as of feature freeze a year ago. :P There's still a long ways to go, so help us focus on the most important issues and on releasing a sound Drupal 8 beta.

Our steady progress toward that first beta release continues as we divide the outstanding beta blockers into actionable sub-steps. Among March's fixed criticals were over 30 beta blockers, more than half the total, showing the community's tight focus on unblocking this milestone.


Note that the number of beta target issues (which are issues that would be good to resolve for the beta, but are not critical enough to block it) continues to increase. As we get closer to beta, it's important to also pay attention to these issues, so we'll be highlighting beta targets more in the coming weeks.

Last week, we fixed 25 critical issues and 24 major issues, and opened 15 criticals and 29 majors. That puts us overall at 118 release-blocking critical issues and 486 major issues.

16 beta-blocking issues were fixed last week. There are still 28 of 142 beta blockers that must be resolved before we can release a Drupal 8 beta.

Where can I help? Top criticals to hit this week

Each week, we check with core maintainers and contributors for the "extra critical" criticals that are blocking other work. These issues are often tough problems with a long history. If you're familiar with the problem space of one of these issues and have the time to dig in, help drive it forward by reviewing, improving, and testing its patch, and by making sure the issue's summary is up to date and any API changes are documented with a draft change record.

More ways to help

Love Drupal and want to help out, but not a coder or unsure where to start? From breaking things (for science!), to designing things; from summarizing issues to writing documentation, there's lots of ways you can contribute! And, there are more than 125 mentors willing to help you!

Our current priority is updating the documentation for Drupal 8. Rich, helpful documentation for Drupal 8 is incredibly important: it's a great way to market Drupal to potential clients, it saves you from writing as much documentation for your existing clients, it empowers new users, site builders, developers, and themers to learn and solve their problems; and, with all the changes that have happened since Drupal 7, it's pretty useful for seasoned Drupal veterans as well!

The documentation team is working on updating:

... for more information, visit the #drupal-docs channel on IRC or jump into the documentation issue queue.

As always, if you're new to contributing to core, check out Core contribution mentoring hours. Twice per week, you can log into IRC and helpful Drupal core mentors will get you set up with answers to any of your questions, plus provide some useful issues to work on.

Notable Commits

The best of git log --after=2014-03-12 --pretty=oneline (253 commits in total):

Amazing work on the configuration system's architecture and dependency management, notably:

  • Issue #2080823 by alexpott, swentel, Wim Leers: Create API to discover content or config entities' soft dependencies and use this to present a confirm form on module uninstall.
  • Issue #2030073 by alexpott: Config cannot be imported in order for dependencies.
    You can now declare dependencies for configuration entities, so you can ensure their dependencies are met before importing them.
  • Issue #2219499 by Berdir, alexpott, Gábor Hojtsy, vijaycs85, swentel: Generalize language config override responsibility.
    This patch simplifies the way that language-specific overrides work and significantly reduces the amount of code that needs to run on sites with only one language.

And, we resolved some of the menu/routing issues that had been causing headaches for developers:

  • Issue #2178725 by pwolanin, crowdcg, effulgentsia, Sutharsan: Make all core menu link machine names and the corresponding route names match.
  • Issue #2226903 by pwolanin, dawehner, tvn, martin107, jessebeach: Step 1: Move static menu links to yml files.
    Now, default menu links are declared the same way as local tasks and local actions. (The next step is to finalize the underlying architecture for this change.)
  • Issue #2207893 by dawehner, pwolanin, jessebeach, Boobaa: Convert menu tree building to a service.
    This removes a whole bunch of the code in menu.inc, makes the menu-building code unit-testable and decouples it from other subsystems. It also unblocks beta-blocking work on the Menu Link API.

In the "things that always annoyed you about Drupal" category,

  • Issue #318975 by sun, Bojhan, linclark: Remove confirmation page after installation.
    When the installer is finished, it drops you on the front page of your new site!
  • Issue #340723 by ParisLiakos, sun, Berdir, glennpratt, Cottser, swentel, tstoeckler, Xano, tim.plunkett, BassistJimmyJam: Make modules and installation profiles only require .info.yml files.
    That means no more empty .module and .profile files! DX FTW!
  • Issue #2122693 by jayeshanandani, YesCT, sun, alexpott, BMDan: Installer does not work on a completely empty settings.php.
    This had been possible in D7.

Other notable commits:

  • Issue #2188613 by Berdir, Xen, andypost: Rename EntityStorageController to EntityStorage.
    This 600K patch was added to make it easier to distinguish between Entity storage classes and Routing controllers.
  • Issue #2213451 by andypost, bdone, benjy, penyaskito, chx, claudiu.cristea, damiankloip, gregboggs, InternetDevels, jessehs, jhedstrom, marvil07, mikeryan, pcambra, Xano, YesCT: Update Migrate API in core.
    This huge update to the migrate API adds support for requirements/dependencies; adds migrations for passwords, URL aliases and config entities; improves entity, bundle and field support; adds lots of Drupal 6 migrations; allows you to set the MigrateSource and MigrateDestination using annotations; and improves documentation. Awesome work Migrate team!
  • Issue #1194136 by Berdir, damiankloip, Wim Leers: Re-organise core cache bins.
    This groups cached items by the type of data (e.g.: rendered HTML, data, entity), rather than the type of item (e.g.: node, block, etc.). This will make cache bins for frequently-requested items (like configuration) smaller with less-frequent updates, which makes it easier for query caches. And, it allows you to tune performance by choosing the most-efficient storage engine / storage location for the type of data (for example, putting the configuration cache table in RAM or on an SSD).
  • Issue #2211553 by andypost, Berdir: Allow usage of entity_reference field widget and formatter for base fields.
    Entity reference fields are being used in core, but there had been no way to use it's widget and formatter.

You can also always check the Change records for Drupal core for the full list of Drupal 8 API changes from Drupal 7.

Drupal 8 Around the Interwebs

Here are a few notable blog posts about Drupal 8 in the past few weeks:

Drupal 8 in "Real Life"

If you would like to get away from the computer, meet other Drupal users, learn about Drupal 8, and have fun at the same time, you can look forward to:

  • NYC Camp on April 10-13: you can get Twig training, there are 13 accepted Drupal 8 sessions, 10 sprints scheduled and there's even a Core summit!
  • DrupalCamp Frankfurt 2014 in Frankfurt, Germany on April 12 and 13; with 8 proposed Drupal 8 sessions on everything from Twig to the Configuration Management Initiative.
  • Drupal Camp Japan 2014 in Kyoto on April 12, featuring an introduction to Drupal 8.
Whew! That's a wrap!

Do you follow Drupal Planet with devotion, or keep a close eye on the Drupal event calendar, or git pull origin 8.x every morning without fail before your coffee? We're looking for more contributors to help compile these posts. You could either take a few hours once every six weeks or so to put together a whole post, or help with one section more regularly. If you'd like to volunteer for helping to draft these posts, please follow the steps here!

Categories: Elsewhere

Wunderkraut blog: Grumpy Swedish developer try to setup for the Acquia Certified Developer exam, and you could not guess what happens next

Planet Drupal - Wed, 02/04/2014 - 23:06

So, I wanted to do the Acquia Certified Developer exam. But I got into trouble before I even start taking the exam.

What got me into Drupal from the beginning were that it is open source, I love open source and what we could together with open source, and I do my daily work on an Ubuntu powered laptop. Why am I writing about that right now? I registered for taking the exam online at www.webassessor.com, and after I set a date and time for the test, I was told to download a piece of software called Sentinel. Sentinel is going to be used when I take the exam, to check me through the web cam, checking it is me doing the test, and I don’t have colleagues helping me out. Fair enough.

I clicked the link, and it was a installer for Windows. Something must be wrong somewhere. I searched the site. It seems that the program I need to install only is available on Windows and Mac. WTF! So I tried to install it with Wine (with that some Windows programs could be run on Ubuntu). Did not work, but I could figure out it was some kind of Flash software.

So I am stuck. I need to have a proprietary OS, I need to install proprietary software to take an exam for an open source system. All this seems totally wrong. Some bad decision has been taking on the road for this exam.

Story will continue (hopefully).

Categories: Elsewhere

Wunderkraut blog: Adding a psuedo field

Planet Drupal - Wed, 02/04/2014 - 21:59

Sometimes you need to display a field that have no input, like a static text or image on each node, or a Facebook like button, or whatever that does not have an input, but you still want to display it as a field, for that you have the hook hook_field_extra_fields.

To display a psuedo field you just need two functions (these functions I added to a custom module called wk_extra_fields)

<?php
/**
* Implements hook_field_extra_fields().
*/
function wk_extra_fields_field_extra_fields() {
  $extra = array();
    // Just adding the psuedo field to the page node type.
    $extra['node']['page'] = array(
      'display' => array(
        'wk_foo' => array(
          'label' => t('WK: Foo'),
          'description' => t('A foo field.'),
          'weight' => -5,
        ),
      ),
    );
  return $extra;
}

/**
* Implements hook_node_view().
*/
function wk_extra_fields_node_view($node, $view_mode, $langcode) {
  // The field is showed in when using full view mode and on page node type.
  if ($view_mode == 'full' && $node->type == 'page') {
    $node->content['wk_foo'] = array(
      '#markup' => '<div class="wk-foo">Foo!</div>',
    );
  }
}
?>


So we use the function wk_extra_fields_field_extra_fields() to create the psuedo field for the page node type, after that we can activate it in the display tab, and choose where to show the field.

When we view the node, the function wk_extra_fields_node_view() is called and the content is displayed.

Image: "Air Guitar Championship" by AxsDeny. Attribution-NonCommercial-NoDerivs License

Categories: Elsewhere

Pages

Subscribe to jfhovinne aggregator - Elsewhere