1.20.x layout.admin.inc layout_locked_message($item, $type = 'layout')

Prepare a message and link based on if a layout item is updated or locked.

See also

layout_break_lock_page()

File

modules/layout/layout.admin.inc, line 2244
Admin page callbacks for the Layout module.

Code

function layout_locked_message($item, $type = 'layout') {
  global $user;

  // The path varies based on the item type.
  $path_type = 'manage';
  $button_title = t('Save layout');
  if ($type === 'menu_item') {
    $path_type = 'menu';
    $button_title = t('Save menu settings');
  }

  $message = '';
  if (!empty($item->locked) && $user->uid !== $item->locked['uid']) {
    $account = user_load($item->locked['uid']);
    $lock_user = theme('username', array('account' => $account));
    $lock_age = format_interval(REQUEST_TIME - $item->locked['updated']);
    $lock_break_url = url('admin/structure/layouts/' . $path_type . '/' . $item->name . '/break-lock', array('query' => array('token' => backdrop_get_token($type . '-' . $item->name)) + backdrop_get_destination()));
    $message = t('Settings on this page are being edited by user !user, and is therefore locked from editing by others. This lock is !age old. Click here to <a href="!break">break this lock</a>.', array('!user' => $lock_user, '!age' => $lock_age, '!break' => $lock_break_url));
  }
  elseif (!empty($item->locked['updated'])) {
    $message = t('This form has unsaved changes. Click "@button" to make changes permanent or "Cancel" to discard changes.', array('@button' => $button_title));
  }

  return $message;
}