Problem

media_wysiwyg_view_mode sub module enables us to restrict view mode options end-user can choose in the media dialog. We can select which type of file we want to restrict view modes and which view modes should be visible by end-users on page `admin/config/media/wysiwyg-view-mode`.

For example I want user can only select 'default', 'preview' view modes for image and tick those options on the page above. However when I go to the WYSIWYG, I cannot see these two options and see view mode 'wysiwyg' instead. I have dig into code and find it is implemented in a reverse logic.

function media_wysiwyg_view_mode_media_wysiwyg_wysiwyg_allowed_view_modes_alter(&$view_modes, &$file) {
  if (variable_get("media_wysiwyg_view_mode_{$file->type}_wysiwyg_restricted_view_modes_status", FALSE) == TRUE) {
    $restricted_view_modes = variable_get("media_wysiwyg_view_mode_{$file->type}_wysiwyg_restricted_view_modes", array());

    foreach ($restricted_view_modes as $restricted_view_mode) {
      if (array_key_exists($restricted_view_mode, $view_modes)) {
        unset($view_modes[$restricted_view_mode]);
      }
    }
  }
}

From the code I have found all selected view modes have been removed from view mode options.

Comments

eric.chenchao’s picture

Assigned: eric.chenchao » Unassigned
Status: Active » Needs review
StatusFileSize
new1.07 KB

Patch is attached:)

Status: Needs review » Needs work

The last submitted patch, 1: media-media_wysiwyg_view_mode_restrict_logic-2479947-1.patch, failed testing.

eric.chenchao’s picture

Status: Needs work » Needs review
StatusFileSize
new1012 bytes

Status: Needs review » Needs work

The last submitted patch, 3: media-media_wysiwyg_view_mode_restrict_logic-2479947-3.patch, failed testing.

eric.chenchao’s picture

I just realized that the original code does the work to allow user disable particular view modes. But I guess select allowed view mode instead of restrict (disable) view mode is more straight forward:)

eric.chenchao’s picture

Status: Needs work » Needs review
dave reid’s picture

Status: Needs review » Needs work

I've gone through and revised the UI to make it more clear how this logic works. This will need a large update since #2158177: Confusing UI for WYSIWYG view modes was committed.

dave reid’s picture

Title: media_wysiwyg_view_mode restrict view mode working as reverse logic » Switch to using an 'allowed view modes' logic instead of restricting view modes

Better title now with the direction.

eelkeblok’s picture

Even though the UI is a huge improvement with #2158177: Confusing UI for WYSIWYG view modes, I still fell in "the trap". Luckily, now the wording in the UI is there to sort of quickly find your mistake. It's still unintuitive, though, so +1 for this change.

rooby’s picture

I don't think this is still relevant now that these settings have been split out to the actual field display admin pages.

joseph.olstad’s picture

Status: Needs work » Closed (outdated)

Based on comment above by @rooby