2014-09-21 2 views
0

я начать использовать Друпал (7) 3 дня назад, и у меня есть небольшая задача:Как добавить кнопку на страницу профиля пользователя в Друпал

Я использую PROFILE2 модуль для создания 2 типа пользователей (candite/работодателя) и я хочу создать кнопку на странице wiew профиля работодателя.

enter image description here

создать новый модуль для того, чтобы проверить, если есть работодатель Профиль:

function ab_candidate_app_profile2_view_alter($build) { 

    $test = $build['field_company_name']['#object']; 
    if(isset($build)) 
    if($test->type == 'employer_'){ 

    // add the button here 
    } 


} 

Спасибо за вашу помощь

EDIT: и при е я делать var_dump ($ билд) я получаю следующий результат:

array (size=12) 
    '#view_mode' => string 'account' (length=7) 
    'field_company_name' => 
    array (size=16) 
     '#theme' => string 'field' (length=5) 
     '#weight' => int 0 
     '#title' => string 'Name' (length=4) 
     '#access' => boolean true 
     '#label_display' => string 'above' (length=5) 
     '#view_mode' => string 'account' (length=7) 
     '#language' => string 'und' (length=3) 
     '#field_name' => string 'field_company_name' (length=18) 
     '#field_type' => string 'text' (length=4) 
     '#field_translatable' => string '0' (length=1) 
     '#entity_type' => string 'profile2' (length=8) 
     '#bundle' => string 'employer_' (length=9) 
     '#object' => 
     object(Profile)[56] 
      public 'pid' => string '6' (length=1) 
      public 'type' => string 'employer_' (length=9) 
      public 'label' => string 'Employer ' (length=9) 
      public 'uid' => string '10' (length=2) 
      public 'created' => string '1411278976' (length=10) 
      public 'changed' => string '1411278976' (length=10) 
      protected 'entityType' => string 'profile2' (length=8) 
      protected 'entityInfo' => 
      array (size=22) 
       ... 
      protected 'idKey' => string 'pid' (length=3) 
      protected 'nameKey' => string 'pid' (length=3) 
      protected 'statusKey' => string 'status' (length=6) 
      protected 'defaultLabel' => boolean false 
      public 'field_company_name' => 
      array (size=1) 
       ... 
      public 'field_logo' => 
      array (size=1) 
       ... 
      public 'field_company_description' => 
      array (size=1) 
       ... 
      public 'field_country' => 
      array (size=1) 
       ... 
      public 'rdf_mapping' => 
      array (size=0) 
       ... 
      public 'entity_view_prepared' => boolean true 
     '#items' => 
     array (size=1) 
      0 => 
      array (size=3) 
       ... 
     '#formatter' => string 'text_default' (length=12) 
     0 => 
     array (size=1) 
      '#markup' => string 'adel' (length=4) 
    'field_logo' => 
    array (size=16) 
     '#theme' => string 'field' (length=5) 
     '#weight' => int 2 
     '#title' => string 'Logo' (length=4) 
     '#access' => boolean true 
     '#label_display' => string 'above' (length=5) 
     '#view_mode' => string 'account' (length=7) 
     '#language' => string 'und' (length=3) 
     '#field_name' => string 'field_logo' (length=10) 
     '#field_type' => string 'image' (length=5) 
     '#field_translatable' => string '0' (length=1) 
     '#entity_type' => string 'profile2' (length=8) 
     '#bundle' => string 'employer_' (length=9) 
     '#object' => 
     object(Profile)[56] 
      public 'pid' => string '6' (length=1) 
      public 'type' => string 'employer_' (length=9) 
      public 'label' => string 'Employer ' (length=9) 
      public 'uid' => string '10' (length=2) 
      public 'created' => string '1411278976' (length=10) 
      public 'changed' => string '1411278976' (length=10) 
      protected 'entityType' => string 'profile2' (length=8) 
      protected 'entityInfo' => 
      array (size=22) 
       ... 
      protected 'idKey' => string 'pid' (length=3) 
      protected 'nameKey' => string 'pid' (length=3) 
      protected 'statusKey' => string 'status' (length=6) 
      protected 'defaultLabel' => boolean false 
      public 'field_company_name' => 
      array (size=1) 
       ... 
      public 'field_logo' => 
      array (size=1) 
       ... 
      public 'field_company_description' => 
      array (size=1) 
       ... 
      public 'field_country' => 
      array (size=1) 
       ... 
      public 'rdf_mapping' => 
      array (size=0) 
       ... 
      public 'entity_view_prepared' => boolean true 
     '#items' => 
     array (size=1) 
      0 => 
      array (size=13) 
       ... 
     '#formatter' => string 'image' (length=5) 
     0 => 
     array (size=4) 
      '#theme' => string 'image_formatter' (length=15) 
      '#item' => 
      array (size=13) 
       ... 
      '#image_style' => string '' (length=0) 
      '#path' => string '' (length=0) 
    'field_company_description' => 
    array (size=16) 
     '#theme' => string 'field' (length=5) 
     '#weight' => int 3 
     '#title' => string 'Description' (length=11) 
     '#access' => boolean true 
     '#label_display' => string 'above' (length=5) 
     '#view_mode' => string 'account' (length=7) 
     '#language' => string 'und' (length=3) 
     '#field_name' => string 'field_company_description' (length=25) 
     '#field_type' => string 'text_long' (length=9) 
     '#field_translatable' => string '0' (length=1) 
     '#entity_type' => string 'profile2' (length=8) 
     '#bundle' => string 'employer_' (length=9) 
     '#object' => 
     object(Profile)[56] 
      public 'pid' => string '6' (length=1) 
      public 'type' => string 'employer_' (length=9) 
      public 'label' => string 'Employer ' (length=9) 
      public 'uid' => string '10' (length=2) 
      public 'created' => string '1411278976' (length=10) 
      public 'changed' => string '1411278976' (length=10) 
      protected 'entityType' => string 'profile2' (length=8) 
      protected 'entityInfo' => 
      array (size=22) 
       ... 
      protected 'idKey' => string 'pid' (length=3) 
      protected 'nameKey' => string 'pid' (length=3) 
      protected 'statusKey' => string 'status' (length=6) 
      protected 'defaultLabel' => boolean false 
      public 'field_company_name' => 
      array (size=1) 
       ... 
      public 'field_logo' => 
      array (size=1) 
       ... 
      public 'field_company_description' => 
      array (size=1) 
       ... 
      public 'field_country' => 
      array (size=1) 
       ... 
      public 'rdf_mapping' => 
      array (size=0) 
       ... 
      public 'entity_view_prepared' => boolean true 
     '#items' => 
     array (size=1) 
      0 => 
      array (size=3) 
       ... 
     '#formatter' => string 'text_default' (length=12) 
     0 => 
     array (size=1) 
      '#markup' => string 'teeeeeeeeeeeeeeeeeeeest' (length=23) 
    'field_country' => 
    array (size=16) 
     '#theme' => string 'field' (length=5) 
     '#weight' => int 4 
     '#title' => string 'Country' (length=7) 
     '#access' => boolean true 
     '#label_display' => string 'above' (length=5) 
     '#view_mode' => string 'account' (length=7) 
     '#language' => string 'und' (length=3) 
     '#field_name' => string 'field_country' (length=13) 
     '#field_type' => string 'list_text' (length=9) 
     '#field_translatable' => string '0' (length=1) 
     '#entity_type' => string 'profile2' (length=8) 
     '#bundle' => string 'employer_' (length=9) 
     '#object' => 
     object(Profile)[56] 
      public 'pid' => string '6' (length=1) 
      public 'type' => string 'employer_' (length=9) 
      public 'label' => string 'Employer ' (length=9) 
      public 'uid' => string '10' (length=2) 
      public 'created' => string '1411278976' (length=10) 
      public 'changed' => string '1411278976' (length=10) 
      protected 'entityType' => string 'profile2' (length=8) 
      protected 'entityInfo' => 
      array (size=22) 
       ... 
      protected 'idKey' => string 'pid' (length=3) 
      protected 'nameKey' => string 'pid' (length=3) 
      protected 'statusKey' => string 'status' (length=6) 
      protected 'defaultLabel' => boolean false 
      public 'field_company_name' => 
      array (size=1) 
       ... 
      public 'field_logo' => 
      array (size=1) 
       ... 
      public 'field_company_description' => 
      array (size=1) 
       ... 
      public 'field_country' => 
      array (size=1) 
       ... 
      public 'rdf_mapping' => 
      array (size=0) 
       ... 
      public 'entity_view_prepared' => boolean true 
     '#items' => 
     array (size=1) 
      0 => 
      array (size=1) 
       ... 
     '#formatter' => string 'list_default' (length=12) 
     0 => 
     array (size=1) 
      '#markup' => string 'Malaysia (MY)' (length=13) 
    '#pre_render' => 
    array (size=1) 
     0 => string '_field_extra_fields_pre_render' (length=30) 
    '#entity_type' => string 'profile2' (length=8) 
    '#bundle' => string 'employer_' (length=9) 
    '#theme' => string 'entity' (length=6) 
    '#entity' => 
    object(Profile)[56] 
     public 'pid' => string '6' (length=1) 
     public 'type' => string 'employer_' (length=9) 
     public 'label' => string 'Employer ' (length=9) 
     public 'uid' => string '10' (length=2) 
     public 'created' => string '1411278976' (length=10) 
     public 'changed' => string '1411278976' (length=10) 
     protected 'entityType' => string 'profile2' (length=8) 
     protected 'entityInfo' => 
     array (size=22) 
      'label' => string 'Profile' (length=7) 
      'plural label' => string 'Profiles' (length=8) 
      'description' => string 'Profile2 user profiles.' (length=23) 
      'entity class' => string 'Profile' (length=7) 
      'controller class' => string 'EntityAPIController' (length=19) 
      'base table' => string 'profile' (length=7) 
      'fieldable' => boolean true 
      'view modes' => 
      array (size=1) 
       ... 
      'entity keys' => 
      array (size=4) 
       ... 
      'bundles' => 
      array (size=2) 
       ... 
      'bundle keys' => 
      array (size=1) 
       ... 
      'label callback' => string 'entity_class_label' (length=18) 
      'uri callback' => string 'entity_class_uri' (length=16) 
      'access callback' => string 'profile2_access' (length=15) 
      'module' => string 'profile2' (length=8) 
      'metadata controller class' => string 'Profile2MetadataController' (length=26) 
      'static cache' => boolean true 
      'field cache' => boolean true 
      'load hook' => string 'profile2_load' (length=13) 
      'translation' => 
      array (size=0) 
       ... 
      'schema_fields_sql' => 
      array (size=1) 
       ... 
      'configuration' => boolean false 
     protected 'idKey' => string 'pid' (length=3) 
     protected 'nameKey' => string 'pid' (length=3) 
     protected 'statusKey' => string 'status' (length=6) 
     protected 'defaultLabel' => boolean false 
     public 'field_company_name' => 
     array (size=1) 
      'und' => 
      array (size=1) 
       ... 
     public 'field_logo' => 
     array (size=1) 
      'und' => 
      array (size=1) 
       ... 
     public 'field_company_description' => 
     array (size=1) 
      'und' => 
      array (size=1) 
       ... 
     public 'field_country' => 
     array (size=1) 
      'und' => 
      array (size=1) 
       ... 
     public 'rdf_mapping' => 
     array (size=0) 
      empty 
     public 'entity_view_prepared' => boolean true 
    '#language' => string 'en' (length=2) 
    '#page' => null 

ответ

1

я решить ее overrieding пользователя-profile.tpl.php с этим кодом:

<?php print render($user_profile); 

    if(isset($user_profile['profile_employer_'])){ 
    $account_info=menu_get_object('user'); 
    $acount_id = $account_info->uid; 

// var_dump($account_info);die(); 

    echo '<a href="/jobPortal/Apply/'.$acount_id.'">Apply Now</a>'; 
    } 
    ?> 

I overied этот файл в следующем пути:

C: \ WAMP \ WWW \ jobPortal \ Themes \ Bartik \ Templates \

+1

рад, что вы нашли решение. Тем не менее, я действительно предлагаю сохранить tpls в чистоте от любой обработки кода php. При таком подходе я столкнулся с довольно сложными проблемами. – fotuzlab

0

Я предполагаю, что вам нужно добавить на дисплее профиля, а не на «вид» из модуля Views. В этом случае вы должны использовать hook_node_view

Вот пример https://www.drupal.org/node/1993368#comment-7406538

или чек больше пояснительный ответ на Drupal 7 hook_node_view add a form to the content of a node. Вы можете добавить кнопку в форму и вызывать на дисплее.

Если вы используете представление из модуля «Просмотры», я бы предложил лучше создать блок в вашем коде и разместить его на конкретной странице, а не изменять представления. Измененные представления могут быть очень трудно поддерживать. Лучше всего хранить их только для отображения содержимого БД, а не для встраивания форм.

Тем не менее, вы могли бы пройти через комментарии к этой теме по поводу аналогичного запроса https://drupal.stackexchange.com/questions/91186/how-do-i-embed-a-node-creation-form-inside-a-view