Drupal: CCK Privacy Felder Sichtbarkeit in Views verwenden

CCK Privacy Felder

Mithilfe des CCK Privacy Moduls können CCK Felder vom Autor des Beitrags als "privat" gekennzeichnet werden, sodass diese im Node für nicht berechtige Personen ausgeblendet werden. Nur Benutzer mit einer entsprechenden Berechtigung können diese Felder sehen.

Sehr praktisch ist dies zum Beispiel in Verbindung mit "Node Profile". So können beispielsweise Adressangaben vor der Öffentlichkeit verborgen werden.

Leider ist das Modul sehr einfach gehalten und bietet keine Views-Integration. Die "privatisierten" Felder werden jedoch logischerweise im View bereitgestellt, jedoch immer angezeigt, egal ob erlaubt oder nicht!

In diesem Artikel stelle ich eine Lösung vor, um dieses Problem mithilfe des PHP View Feldes aus dem Modul "Views Custom Field zu lösen.

Verwendete Module:

Vorgehensweise:

  1. Privates CCK Feld dem View wie gewohnt hinzufügen, aber "Von der Anzeige ausschließen" aktivieren.
  2. Ein Views Custom Field: PHP dem View HINTER dem Originalfeld hinzufügen!
  3. Als Wert des PHP-Feldes den folgenden Code verwenden:

  1.  
  2. //Zugriff pruefen
  3. if(!privacy_is_private('field_uprofile_name', $data->node_users_nid)){
  4.   echo $data->node_users_node_data_field_uprofile_name_field_uprofile_name_value;
  5. }

Die korrekten Variablennamen könnt ihr herausfinden, indem ihr das Feld zunächst mit einem

  1. var_dump($data);

abfeuert.
Achtung: Den Namen des CCK-Feldes entnehmt ihr am besten der Feldübersicht ("Felder anzeigen") im Node-Type.

Die oberhalb dargestellten Bezeichner einfach gegen eure austauschen, das war's!

Nun wird der Inhalt des Feldes nur noch angezeigt, wenn es öffentlich ist. Achtung: Dies gilt für alle Rollen. Um die Bedingungen noch weiter zu verfeinern, sind zusätzliche Arbeiten nötig. Dies soll aber nicht Teil des Artikels sein.

Screenshots habe ich als Beispiel angehängt.

Viel Spaß damit!

AttachmentSize
Original CCK Datenfeld34.05 KB
Views Customfield PHP35.8 KB
Feldübersicht Beispiel12.51 KB
Einordnung:

Comments

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Internal paths in single or double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or path. Paths to files in single or double quotes, written as "files:somefile.ext", for example, are replaced with the appropriate URL that can be used to download the file.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><blockquote>
  • Lines and paragraphs break automatically.
  • Pairs of<blockquote> tags will be styled as a block that indicates a quotation.
  • You can enable syntax highlighting of source code with the following tags: <c>, <cpp>, <css>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <php>, <python>, <ruby>, <smarty>, <xml>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Textual smileys will be replaced with graphical ones.
  • Each email address will be obfuscated in a human readable fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.