Jump to content


Photo

Change "Name" field label for users to "Username"

Module

  • Please log in to reply
No replies to this topic

#1 Soma

Soma

    Hero Member

  • Moderators
  • 3,205 posts
  • 1757

  • LocationSH, Switzerland

Posted 10 May 2012 - 10:00 AM

Some time ago there was a question if it's possible to change the "name" field on the users to "Username".

Here's how I answered with a module example. May it be helpful to someone.


<?php

class UserNameLabel extends WireData implements Module{
	
	public static function getModuleInfo() {
		return array(
			'title' => __('UserNameLabel', __FILE__), // Module Title
			'version' => 100,
			'summary' => __('Overwrite User Name Label', __FILE__), // Module Summary
			'autoload' => true
			);
	}

	public function init() {
		// only add hook if on user pages
		if(strpos($_SERVER['REQUEST_URI'],'/users/') !== FALSE )
			$this->addHookAfter("Inputfield::render", $this, "changeLabel");
	}

	public function changeLabel($event){
		$inputfield = $event->object;
		// only if the right inputfield
		if(!$inputfield instanceof InputfieldName ) return;
		// overwrite the label
		return $event->object = $inputfield->label = __("Username");
	}

}

Attached Files


@somartist | modules created | support me, flattr my work flattr.com






Also tagged with one or more of these keywords: Module

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users