Good understanding of the name attribute of the input fields

hello all of you 

I would like to know if the attributes on the new object (ElggObject, ElggGroup) created on elgg can only have as attribute name on an input field or other than (title and description), because I have created an ElggGroup object which here is the form

​// title
echo elgg_view_field([
    '#type' => 'text',
    '#label' => elgg_echo('camerproject:title'),
    'name' => 'title',
    'value' => elgg_extract('title', $vars),
    'required' => true,
]);

echo elgg_view_field([
  '#type' => 'file',
  '#label' => elgg_echo('camerproject:logoproject'),
  '#help' => elgg_echo('camerproject:edit:icon:limit', [$upload_limit]),
  'name' => 'icon',
  'value' => elgg_extract('icon', $vars),
  'required' => true,
]);

 echo elgg_view_field([
     '#type' => 'plaintext',
     '#label' => elgg_echo('camerproject:summery'),
     'name' => 'summery',
     'value' => elgg_extract('summery', $vars),
     'required' => true,
 ]);

 echo elgg_view_field([
     '#type' => 'dropdown',
     '#label' => elgg_echo('camerproject:progress'),
     'name' => 'progress',
     'options_values' => $progress,
     'value' => elgg_extract('progress', $vars),
     'required' => true,
  ]);

 

and when I try to interpret my different attributes. of which here a function defined for this is:

/**
 * {@inheritDoc}
 * @see ElggEntity::getURL()
 */
public function getURL() {
        $friendly_title = elgg_get_friendly_title($this->getDisplayName());

        return elgg_normalize_url("camerproject/profile/{$this->guid}/{$friendly_title}");
} 

but the function getDisplayName () does not work the other attributes except on those whose name of the input field is (title and description)

 

Please help me,

regards,

  • this is my action edit file 

    <?php
    
    /**
    
     * Elgg camerproject plugin edit action.
    
     *
    
     * If editing an existing project, only the "project_guid" must be submitted. All other form
    
     * elements may be omitted and the corresponding data will be left as is.
    
     *
    
     * @package ElggGroups
    
     */
    
    
    elgg_make_sticky_form('camerproject/edit');
    
    
    $title = get_input('title');
    
    $sectorindustry = get_input('sectorindustry');
    
    $devise = get_input('devise');
    
    
    if (empty($sectorindustry) || empty($devise)) {
    
    return elgg_error_response(elgg_echo('error:missing_data'));
    
    }
    
    
    $guid = (int) get_input('guid');
    
    $is_new_project = false;
    
    if (!empty($guid)) {
    
    $project = get_entity($guid);
    
    if (!($project instanceof Camerproject) || !$project->canEdit()) {
    
    return elgg_error_response(elgg_echo('actionunauthorized'));
    
    }
    
    } else {
    
    $is_new_project = true;
    
    $project = new Camerproject();
    
    
    if (!$project->save()) {
    
    return elgg_error_response(elgg_echo('save:fail'));
    
    }
    
    }
    
    
    $user = elgg_get_logged_in_user_entity();
    
    
    
    $project->name = get_input($title);
    
    $project->description = get_input('description');
    
    $project->progress = get_input('progress');
    
    $project->setSectorindustry($sectorindustry);
    
    $project->activity = get_input('activity');
    
    $project->markettype = get_input('markettype');
    
    $project->offertype = get_input('offertype');
    
    $project->turnover = get_input('turnover');
    
    $project->setDevise($devise);
    
    $project->ville = get_input('location');
    
    $project->projectwebsite = get_input('projectwebsite');
    
    $project->projectblog = get_input('projectblog');
    
    $project->projectpitch = get_input('projectpitch');
    
    
    
    $tool_entity = !$is_new_project ? $project : null;
    
    
    $tool_options = camerproject_get_project_tool_options($tool_entity);
    
    
    if ($tool_options) {
    
    
    foreach ($tool_options as $project_option) {
    
    $option_toggle_name = $project_option->name . "_enable";
    
    $option_default = $project_option->default_on ? 'yes' : 'no';
    
                    
    
    $value = get_input($option_toggle_name);
    
    // if already has option set, don't change if no submission
    
    if ($project->$option_toggle_name && $value === null) {
    
    continue;
    
    }
    
    
    $project->$option_toggle_name = $value ? $value : $option_default;
    
    }
    
    }
    
    
    // Project membership - should these be treated with same constants as access permissions?
    
    
    $value = get_input('membership');
    
    
    if ($project->membership === null || $value !== null) {
    
    
    $is_public_membership = ( $value == ACCESS_PUBLIC );
    
    
    $project->membership = $is_public_membership ? ACCESS_PUBLIC : ACCESS_PRIVATE;
    
    }
    
    
    $project->setContentAccessMode((string)get_input('content_access_mode'));
    
    
    if ($is_new_project) {
    
    $project->access_id = ACCESS_PUBLIC;
    
    }
    
    
    $old_owner_guid = $is_new_project ? false : $project->owner_guid;
    
    
    $value = get_input('owner_guid');
    
    $new_owner_guid = ($value === null) ? $old_owner_guid : (int)$value;
    
    
    if (!$is_new_project && $new_owner_guid && $new_owner_guid != $old_owner_guid) {
    
    // verify new owner is member and old owner/admin is logged in
    
    if ($project->isMember(get_user($new_owner_guid)) && ($old_owner_guid == $user->guid || $user->isAdmin())) {
    
    $project->owner_guid = $new_owner_guid;
    
    if ($project->container_guid == $old_owner_guid) {
    
    
    $project->container_guid = $new_owner_guid;
    
    }
    
    
    $metadata = elgg_get_metadata(array(
    
    'guid' => $guid,
    
    'limit' => false,
    
    ));
    
    if ($metadata) {
    
    foreach ($metadata as $md) {
    
    if ($md->owner_guid == $old_owner_guid) {
    
    $md->owner_guid = $new_owner_guid;
    
    $md->save();
    
    }
    
    }
    
    }
    
    }
    
    }
    
    
    
    if ($is_new_project) {
    
    // if new project, we need to save so project acl gets set in event handler
    
    if (!$project->save()){
    
    return elgg_error_response(elgg_echo('camerproject:save_error'));
    
    }
    
    }
    
    
    if (elgg_get_plugin_setting('hidden_camerproject', 'camerproject') == 'yes') {
    
    
    $value = get_input('vis');
    
            
    
    if ($is_new_project || $value !== null) {
    
    
    $visibility = (int)$value;
    
    
    if ($visibility == ACCESS_PRIVATE) {
    
    // Make this project visible only to project members. We need to use
    
    // ACCESS_PRIVATE on the form and convert it to project_acl here
    
    // because new camerproject do not have acl until they have been saved once.
    
    $visibility = $project->project_acl;
    
    
    // Force all new project content to be available only to members
    
    $project->setContentAccessMode(ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY);
    
    }
    
    
    $project->access_id = $visibility;
    
    }
    
    }
    
    
    if ((bool) get_input('remove_icon', false)) {
    
        
    
        $project->deleteIcon();
    
        
    
    } else {
    
        $project->saveIconFromUploadedFile('icon');
    
    }
    
    
    if (!$project->save()) {
    
    return elgg_error_response(elgg_echo('camerproject:save_error'));
    
    }
    
    
    elgg_clear_sticky_form('camerproject/edit');
    
    
    if ($is_new_project) {
    
    
    elgg_set_page_owner_guid($project->guid);
    
    $project->join($user);
    
    
    elgg_create_river_item([
    
    'view' => 'river/object/camerproject/create',
    
    'action_type' => 'create',
    
    'subject_guid' => $user->guid,
    
    'object_guid' => $project->guid,
    
    ]);
    
    }
    
    
    system_message(elgg_echo("camerproject:saved"));
    
    
    forward($project->getURL());
    
    
    //return elgg_ok_response('', elgg_echo('camerproject:saved'), $project->getUrl());
  • this in my class Camerproject : 

    <?php
    
    
    /**
    
     * Description of Camerproject
    
     *
    
     * @author Kana
    
     */
    
    
    class Camerproject  extends ElggGroup{
    
       
    
        const SUBTYPE = 'camerproject';
    
        const AFFECTED_SECTORINDUSTRY = 'affected';
    
        const USE_DEVISE = 'use';
    
         
    
       
    
    /**
    
    * {@inheritDoc}
    
    * @see ElggGroup::initializeAttributes()
    
    */
    
      protected function initializeAttributes() {
    
            parent::initializeAttributes();
    
            $site = elgg_get_site_entity();
    
            $this->attributes['subtypes'] = self::SUBTYPE;
    
            $this->attributes['owner_guid'] = $site->guid;
    
            $this->attributes['container_guid'] = $site->guid;
    
        }
    
    
    /**
    
     * {@inheritDoc}
    
     * @see ElggGroup::canComment()
    
     */
    
    public function canComment($user_guid = 0, $default = null) {
    
            return false;
    
    }
    
    
    /**
    
     * {@inheritDoc}
    
     * @see ElggEntity::getURL()
    
     */
    
    public function getURL() {
    
            $friendly_title = elgg_get_friendly_title($this->getDisplayName());
    
    
            return elgg_normalize_url("camerproject/profile/{$this->guid}/{$friendly_title}");
    
    } 
    
    /**
    
     * Set the sectorindustry affected by this camerproject
    
     *
    
     * @param int[] $sectorindustry
    
     *
    
     * return bool
    
     */
    
     public function setSectorindustry($sectorindustry) {
    
    
            if (!is_array($sectorindustry)) {
    
                    return false;
    
            }
    
                   
    
            $existing_sectorindustry = $this->getSectorindustry([
    
                    'limit' => false,
    
                    'callback' => function($row) {
    
                            return (int) $row->guid;
    
                    },
    
            ]);
    
    
            $result = true;
    
    
            // remove sectorindustry
    
            $remove_sectorindustry = array_diff($existing_sectorindustry, $sectorindustry);
    
            foreach ($remove_sectorindustry as $sectorindustry_guid) {
    
                    $result &= $this->removeRelationship($sectorindustry_guid, self::AFFECTED_SECTORINDUSTRY);
    
            }
    
    
            // add new sectorindustry
    
            $add_sectorindustry = array_diff($sectorindustry, $existing_sectorindustry);
    
            foreach ($add_sectorindustry as $sectorindustry_guid) {
    
                    $result &= $this->addRelationship($sectorindustry_guid, self::AFFECTED_SECTORINDUSTRY);
    
            }
    
    
            return $result;
    
        }
    
    
    /**
    
     * Return affected sectorindustry
    
     *
    
     * @param array $options additional options for elgg_get_entities_from_relationship
    
     *
    
     * @see elgg_get_entities_from_relationship()
    
     *
    
     * @return bool|int|Sectorindustry]
    
     */
    
        public function getSectorindustry($options = []) {
    
    
            $defaults = [
    
                    'type' => 'object',
    
                    'subtype' => Sectorindustry::SUBTYPE,
    
                    'relationship' => self::AFFECTED_SECTORINDUSTRY,
    
            ];
    
    
            $options = array_merge($options, $defaults);
    
    
            return $this->getEntitiesFromRelationship($options);
    
        }
    
    
    
    
    /**
    
     * Set the devise use by this camerproject
    
     *
    
     * @param int[] $devise
    
     *
    
     * return bool
    
     */
    
    
    public function  setDevise($devise){
    
        
    
        if(!is_array($devise)){
    
            
    
            return false;
    
        }
    
        
    
        $existing_devise = $this->getDevise([
    
            'limit' => false,
    
            'callback' => function($row){
    
              return (int) $row->guid;
    
            },
    
        ]);
    
            
    
       $result = true;
    
       
    
       // remove devise
    
       
    
       $remove_devise = array_diff($existing_devise, $devise);
    
       
    
       foreach ($remove_devise as $devise_guid){
    
           $result &= $this->removeRelationship($devise_guid, self::USE_DEVISE);
    
       }
    
       
    
       // add devise 
    
       $add_devise = array_diff($devise, $existing_devise);
    
       
    
       foreach ($add_devise as $devise_guid){
    
           
    
           $result &= $this->addRelationship($devise_guid, self::USE_DEVISE);
    
       }
    
       
    
       return $result;
    
    }
    
    
    /**
    
     * Return use devise
    
     *
    
     * @param array $options additional options for elgg_get_entities_from_relationship
    
     *
    
     * @see elgg_get_entities_from_relationship()
    
     *
    
     * @return bool|int|Devise]
    
     */
    
    public function getDevise($options = []){
    
       $defaults = [
    
        'type' => 'object',
    
        'subtype' => Devise::SUBTYPE,
    
        'relationship' => self::USE_DEVISE,
    
      ];
    
    
      $options = array_merge($options, $defaults);
    
    
      return $this->getEntitiesFromRelationship($options);  
    
        
    
    }
    
    
    }
  • I take it CamerProject extends ElggGroup?? with a different 'subtype'?

    small error in your code

    $project->name = get_input($title);

    should be eighter $project->name = $title; or $project->name = get_input('title');

  • I corrected. but it does not always work but I do not know about ??? please help me

  • @foka_patrick There is a plugin for it.
  • 1. UnZip/Activate

    2. Go to Dashboard -> Administer section -> Groups -> Subtypes

    3. Add new subtype for group (e.g. camerproject) -> Submit

    4. Choose options. You can set your own page identifier like as 'groups/camerproject'. In this case your 'camerprojects' will located in such URLs site.com/groups/camerproject/profile/{GUID}/{NAME}

    (screenshot can say more than words).

    Additional, you should translate some language keys.

    Also, keep in your mind that you need to enable/disable your own hooks/actions for your project in your own plugin/theme.

    Of course, welcome to PRs on the plugin's page.