How to change default prefix "Create/Update" that comes with CRUD? - laravel

How can i change, prefix that comes with CRUD operation ie CREATE / UPDATE in laravel NOVA?
And if i can change them, how can i apply translations on them?
prefix "Create" is shown in image.

There is no need to install packages or edit core files 😱. You can easily change this in the language files. Assuming that your app's locale is set to en, the translation file can be found in /resources/lang/vendor/nova/en.json.
In this file, go to the entry you need to edit, in this case
"Create :resource": "Create :resource"
and change the value to what you want it to be. For example, changing it to
"Create :resource": "Create a new :resource"
will turn the text into

Note: You don't need to change core files, You can also do this following way
"Create :resource": "Create :resource"
to "Create :resource": "Create a new :resource"
lets say resource name is post. then the new heading will become Create a new Post You can change heading the way you like from here.
And it will update your heading, without updating core files. #Govert Verschuur provided this solution.
Other way around is -> Default name "Create/Update" is provided in Panel.php file.
/**
* Get the default panel name for a create panel.
*
* #param \Laravel\Nova\Resource $resource
* #return string
*/
public static function defaultNameForCreate(Resource $resource)
{
return __('Create :resource', [
'resource' => $resource->singularLabel(),
]);
}
/**
* Get the default panel name for the update panel.
*
* #param \Laravel\Nova\Resource $resource
* #return string
*/
public static function defaultNameForUpdate(Resource $resource)
{
return __('Update :resource', [
'resource' => $resource->singularLabel(),
]);
}
Change the String here and boom, it will solve your issue.
And as far as translation is concerned is already applied, You just need to provide translation in your en.json or any other file.
Note:
Translation will only be applied on final string, so Add "Create" / "Update" with your label name and if label is not set then with your default name.

Related

how to remove all checkboxes from resource list in laravel nova?

I have a laravel nova app. Like other nova app on resource list it shows a checkbox before every rows. and a option of select all.
I want to remove those checkboxes from the resource list.
Thanks.
As described in comments above, the cleanest way will be limiting user permissions. Otherwise, there are some hacky ways to try:
1. Empty actions
If you resource has no actions, then in your resource file override availableActions method:
/**
* Get the actions that are available for the given request.
*
* #param \Laravel\Nova\Http\Requests\NovaRequest $request
* #return \Illuminate\Support\Collection
*/
public function availableActions(NovaRequest $request)
{
return [];
}
2. Hiding with css.
Put this in custom tool, or override layout.blade.php.
EDIT Found a better way of hiding with css thanks to #Max's comment
div[dusk="products-index-component"] div[dusk="select-all-dropdown"],
div[dusk="products-index-component"] .table td:first-child,
div[dusk="products-index-component"] .table th:first-child {
display: none !important;
}
3. Custom resource-index component.
Create custom tool and override /nova/resources/js/views/Index.vue. This is where checkbox showing logic goes on.
/**
* Determine whether to show the selection checkboxes for resources
*/
shouldShowCheckBoxes() {
return (
Boolean(this.hasResources && !this.viaHasOne) &&
Boolean(
this.actionsAreAvailable ||
this.authorizedToDeleteAnyResources ||
this.canShowDeleteMenu
)
)
},

How to set possible date input formats for Typo3 6.2 Extbase Extension?

I made an extension with the Extension Builder in Typo3 6.2 using Fluid 6.2 and Extbase 6.2.
I made Appointment-Objects with a date property.
I want to enter the date in the format "dd.mm.yyyy".
So I tried this:
And it gives this error:
I'm clueless as I'm not familiar with this and I want to solve this in a nice way.
My createAction code is simply generated by the extension builder and therefore looks like this:
/**
* action create
*
* #param \JH\Appmgmt\Domain\Model\Appointment $newAppointment
* #return void
*/
public function createAction(\JH\Appmgmt\Domain\Model\Appointment $newAppointment) {
$this->addFlashMessage('The object was created. Please be aware that this action is publicly accessible unless you implement an access check. See Wiki', '', \TYPO3\CMS\Core\Messaging\AbstractMessage::ERROR);
$this->appointmentRepository->add($newAppointment);
$this->redirect('list');
}
Now I realize that if I change something here in order for the format to work I would have to do the same thing in the updateAction and maybe others that I don't know about yet.
I also desperately tried to format it to the desired format somehow in the partial but that was bound to fail - same result:
<f:form.textfield property="appointmentDate" value="{appointment.appointmentDate->f:format.date(format:'Y-m-d\TH:i:sP')}" /><br />
So that's where I need your help - I don't know where and how to globally allow this date format since I will be needing it for other fields as well.
The only other thing I can think of is changing something in the domain model:
/**
* appointmentDate
*
* #var \DateTime
*/
protected $appointmentDate = NULL;
but I don't know how I should approach this. :(
Anyone an idea?
You send a date that is not formatted correctly as a date Object.
that's exactly what the error says.
What you can do is re-format the date you send so that it arrives at your controller action as a valid argument for your object. this is done with an initialize action that invokes a property mapping.
a clear example can be found here:
http://www.kalpatech.in/blog/detail/article/typo3-extbase-datetime-property-converter.html
the part that you need is:
// Here we convert the property mapping using the property mapper
public function initializeAction() {
if ($this->arguments->hasArgument('newCalendar')) {
$this->arguments->getArgument('newCalendar')->getPropertyMappingConfiguration()->forProperty('startdate')->setTypeConverterOption('TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',\TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter::CONFIGURATION_DATE_FORMAT,'d-m-Y');
}
}
You could also disable the validation of the date arguments to your controller and create a valid date Object from your 'date' and then use setAppointmentDate($yourNewDateObject).
You then go round the extbase validation, what is not a good practise.

Typo3 extbase validating custom or manual objects

I have created extbase extension, there for some reason I need to create object manually in create action.
My create action looks like this,
/**
* action create
*
* #return void
*/
public function createAction() {
$newObj = new \TYPO3\Myext\Domain\Model\Modelname();
$newObj->setMyval('value');
$this->myrepository->add($newObj);
}
Here the problem is its not validating for require field, captcha etc even if I mention #validate NotEmpty in model.
So how to make the validation of manually created object ?
It should throw error to form like out-of-the-box features.
Thank you.
Out of the box validation is only triggered on constructing model objects from GET/POST parameters according to your controller actions signature.
It should look something like this:
/**
* action create
* #param \TYPO3\Myext\Domain\Model\Modelname $newObject
* #return void
*/
public function createAction(\TYPO3\Myext\Domain\Model\Modelname $newObject) {
$this->myrepository->add($newObj);
}
Take a look at the extension_builder, create a model and let the new/create action be generated for you. That will give you a good example on the create action as well as on the new action where the form is being rendered.

typo3 extbase validate for multiple records

I have written one extbase plugin, that creates the FE users from front end form.
The create action is something like this
/**
* action create
*
* #param \TYPO3\Usermanagement\Domain\Model\Users $newUsers
* #return void
*/
public function createAction(\TYPO3\Usermanagement\Domain\Model\Users $newUsers) {
$this->usersRepository->add($newUsers);
}
Here I want to validate for same username or email already exists or not.
How can I do this ?
Any suggestions ?
Thank you.
You don't need to bind a $newUser as an action's param, instead you can just read some fields using $this->request->hasArgument('something') and $this->request->getArgument('something') to validate properties yourself, and create new user object manually like.
public function createAction() {
$newUsers = new \TYPO3\Usermanagement\Domain\Model\Users();
// do something with $newUsers object...
$this->usersRepository->add($newUsers);
}
It will not throw an exception in case when there's no valid user object in the request, so it will allow you to handle form's error as you want/need.
It will also allow you to use some preprocessing before saving ie hashing/salting passwords.

How to add a note for an attribute in magento?

I have created a new product attribute in Magento using the admin panel. But I can't find where to put a note for that attribute (that is the text that should display below the input field as extra info about it.)
Am I missing something, or is this not possible to implement in the admin panel?
This is an example of how a note on an attribute would look like:
I am using Magento 1.7 CE.
It's not possible through the admin Panel.
By the way, you really should add your attributes programatically. (if you database crash, your done for).
What you need is to modify the column "note" of the eav_attribute table.
You can modify it with the updateAttribute() command in an upgrade script. Example :
$installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, 'color', 'note','my comment');
hmm this might be a bit late, but anyway, I had a similar problem today and solved it in the following intuitive way:
first my problem:
howto get in the extended-search-page the attributes in the a custom order?
for this I've found something here:
http://www.magentocommerce.com/boards/viewthread/11782/
-- they tell:
U might use the custom not used field ´note´ from the mysql table: ´eav_attribute´
therefor you can change in
app\code\core\Mage\CatalogSearch\Model\Advanced.php
the order-by
i.e.
from: ->setOrder('main_table.attribute_id', 'asc')
to: ->setOrder('main_table.note', 'asc')
But then, you still have the prob, how to edit the things properly, without edit anything directly by in a mysql-client; from now on, I have had your problem, my solution:
Model: get/set
in app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php
grep: class Mage_Eav_Model_Entity_Attribute_Abstract ex
add: best after search: "n getName"
/**
* Get attribute note
*
* #return string
*/
public function getNote()
{
return $this->_getData('note');
}
/**
* Set attribute note
*
* #param string $name
* #return Mage_Eav_Model_Entity_Attribute_Abstract
*/
public function setNote($note)
{
return $this->setData('note', $note);
}
Controler: set
in app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php
(o.k. this is a shortcut, I think you can add some attributes to "note_text" somewhere, but I have no plan from magento)
search for: "default value" and extend:
from:
$defaultValueField = $model->getDefaultValueByInput($data['frontend_input']);
if ($defaultValueField) {
$data['default_value'] = $this->getRequest()->getParam($defaultValueField);
}
to:
$defaultValueField = $model->getDefaultValueByInput($data['frontend_input']);
if ($defaultValueField) {
$data['default_value'] = $this->getRequest()->getParam($defaultValueField);
$data['note'] = $this->getRequest()->getParam('note_text');
}
View:
in ./app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Main/Abstract.php
after:
$fieldset->addField('default_value_text', 'text', array(
add:
$fieldset->addField('note_text', 'text', array(
'name' => 'note_text',
'label' => Mage::helper('eav')->__('Note Value'),
'title' => Mage::helper('eav')->__('Note Value'),
'value' => $attributeObject->getDefaultValue(),
));
finally I've initiallized the note-field in the mysql table by:
update eav_attribute set note=lpad(attribute_id,10,'0000000000') where attribute_id not in(84,100);
where attributes with the id 84 and 100 have had already some notes.

Resources