For this to work out of the box, we would probably want to grab the first image field of every entity as a default value, and use the site's logo as a default.

Files: 
CommentFileSizeAuthor
#10 representative_image--7.x-1.x--1988658-10-defaults.patch7.35 KBalberto56
PASSED: [[SimpleTest]]: [MySQL] 325 pass(es). View
#9 rep_img_defaults.patch7.35 KBbleen
PASSED: [[SimpleTest]]: [MySQL] 325 pass(es). View
#7 rep_img_defaults.patch19.72 KBbleen
PASSED: [[SimpleTest]]: [MySQL] 155 pass(es). View
#2 representative_image--1988658-2--sensible-defaults.patch4.85 KBalberto56
PASSED: [[SimpleTest]]: [MySQL] 151 pass(es). View

Comments

bleen’s picture

Title: More sensible defaults » More sensible defaults on installation

This is an excellent idea!

alberto56’s picture

Status: Active » Needs review
FileSize
4.85 KB
PASSED: [[SimpleTest]]: [MySQL] 151 pass(es). View

Here is a patch that does the following:

(1) representative_image_get_field($entity_type, $bundle) will now return the first possible image/media field if one has not yet been set (or if it has not been set to none).
(2) a new function representative_image_default($entity_type = NULL, $bundle = NULL), which tries to determine a default for for entity types and bundles (for example page nodes), and falls back to defaults for entity type (e.g. node) defaults, and, if there is still no result, falls back to a defined global default, which itself defaults to the logo.

The global default is tested, and the rest does not break anything, but should be considered as undocumented until it is tested, which will probably happen in #1979962: Come up with a more robust way to handle default_representative image

bleen’s picture

+++ b/representative_image.moduleundefined
@@ -142,14 +149,49 @@ function representative_image($entity, $entity_type) {
+ *   A bundle like "page"

needs a @return

+++ b/representative_image.moduleundefined
@@ -142,14 +149,49 @@ function representative_image($entity, $entity_type) {
+    $default = variable_get('representative_image_default', preg_replace('/^' . str_replace('/', '\/', $base_url) . '\//', '', theme_get_setting('logo')));

I'm concerned about using logo as a default... I think this needs to be configurable. It makes sense for things like OpenGraph meta tags, but not for most internal pages (ex. a view to replace admin/content).

+++ b/representative_image.moduleundefined
@@ -142,14 +149,49 @@ function representative_image($entity, $entity_type) {
+  if ($default) {
+    $default = $base_url . '/' . $default;
+  }
+
+  return $default;

can this be:
return $default ? $base_url . '/' . $default : '';

This way the return when all else fails is explicitly empty strnig

alberto56’s picture

Title: More sensible defaults on installation » More sensible defaults on installation, and admin UI for handling defaults
Status: Needs review » Needs work

Makes sense. The way to make the logo configurable is to set an administrative UI, and a proper API; the logo is an out-of-the-box default, and can (for now) be changed via drush, which is no longer enough. I've set #1979962: Come up with a more robust way to handle default_representative image issue as a duplicate of this one, so that the patch being worked on here can be tweaked to do everything we need.

If use of the logo can be changed via an admin interface and an API, do you still have objections?

bleen’s picture

marked #1990974: When no representative image is present, and no default, the return value is http://example.com/ as a duplicate of this ... we should make sure here that if all else fails (and a user has no default set) that we simply return an empty string for the representative image.

bleen’s picture

If use of the logo can be changed via an admin interface and an API, do you still have objections?

Just noticed this question ... answer:nope

bleen’s picture

Status: Needs work » Needs review
FileSize
19.72 KB
PASSED: [[SimpleTest]]: [MySQL] 155 pass(es). View

how bout this ... slightly different approach but I think it covers all the cases.

https://www.evernote.com/shard/s17/sh/aca97fd1-25cf-42e7-ab72-0bd3b7bed1...

bleen’s picture

... Looking at that screenshot I realize that those drop down options need much better names and the description could probably use some love...

bleen’s picture

FileSize
7.35 KB
PASSED: [[SimpleTest]]: [MySQL] 325 pass(es). View

This is more clear ... AND uncommented the test that I had commented out for local testing.

alberto56’s picture

FileSize
7.35 KB
PASSED: [[SimpleTest]]: [MySQL] 325 pass(es). View

Good work, nice and simple.

I just fixed a typo: "faound" => "found"

If it passes now we are good to go.

Albert.

bleen’s picture

Status: Needs review » Reviewed & tested by the community

go fer it :)

bleen’s picture

Status: Reviewed & tested by the community » Fixed

Committed ... woot woot

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.