required rule not working in model for yii2basic - yii2-basic-app

i have generated a model by gii for my table which by default generated required rule for some database field in rules section. But i don't want some of the fields of them to be required so i simply removed them from required portion. but this is not working.
what i have by default is this
[['grp_name', 'sub_grp', 'member_name', 'fathers_name', 'd_o_b', 'occupation', , 'address', 'phone_no', 'nomniee_one', 'per_allotment_one', 'per_allotment_two' ], 'required'],
but i don't want to make 'per_allotment_two' required so iremoved it and made this
[['grp_name', 'sub_grp', 'member_name', 'fathers_name', 'd_o_b', 'occupation', , 'address', 'phone_no', 'nomniee_one', 'per_allotment_one' ], 'required'],
but got this error

If the per_allotment_two is not required means in the database make the
per_allotment_two has default null.Otherwise provide some default value to it.
Then remove the per_allotment_two from the model in the rules section.It will work.

Related

Undefined array key "relation_type"

Im having some issues with a backpack project im doing.
What im trying to do change the way the PermissionsManager displays the check boxes when editing a user.
I have managed to create the custom CRUD files and i know that these files are working as i can edit some of the basic fields to add additional user fields.
The code im using to add the relationship is..
$this->crud->addField(
[ // relationship
'name' => 'permission', // the method on your model that defines the relationship
'type' => "relationship",
// OPTIONALS:
// 'label' => "Category",
// 'attribute' => "title", // attribute on model that is shown to user
// 'placeholder' => "Select a category", // placeholder for the select2 input
]
);
The error i get then i try to access the page is..
Undefined array key "relation_type"
Any ideas on what might be causing this?
thanks!
I think you are getting that error because the relationship name is permissions (plural) and not permission (singular).
Let me know if that's the case.
Cheers

TYPO3 TCA pages types add Tab

I want to add an existing tab to special pagetype.
For example tab "social media" to pagetype 254 (folder).
So i used mergeRecursiveWithOverrule like this, but then i redefine all.
Can i only add a single tab?
\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule(
$GLOBALS['TCA']['pages'],
[
'types' => [
254 => [
'showitem' => '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general, --palette--;;standard, --palette--;;titleonly, ,
--div--;LLL:EXT:seo/Resources/Private/Language/locallang_tca.xlf:pages.tabs.socialmedia, --palette--;;opengraph, --palette--;;twittercards,
,...
,
'
]
],
],
);
Thanks
ExtensionManagementUtility::addToAllTCAtypes() is what you are looking for, especially the third parameter.
Parameters of addToAllTCAtypes():
Name of the table to which the fields should be added.
Comma-separated string of fields, the same syntax used in the showitem property of types in TCA.
Optional: record types of the table where the fields should be
added, see types in TCA for details.
Optional: position ('before' or 'after') in relation to an existing
field.
Docs: Extension Development -> Extending the TCA array -> Customization Examples

Wagtail form builder with additional constant fields

I have created a quiz with wagtail form builder, but I need the form to contain some fields which are constant. For example, I have the following:
Name
Email
Employee id
[form builder fields]
How do I integrate fields [1-3] in the form builder to show up on all quizzes?
A simple way to do this is to override the get_form_fields method on your FormPage model.
This method simply returns a query for all stored FormFields on the FormPage model. We can add instances of FormField as needed and this will make the fields available in the form (view). They will also be available in form reports and emails.
1 - Override get_form_fields in your FormPage class.
In myapp/models.py wherever you have defined your FormPage model, add the following:
class FormPage(AbstractEmailForm):
# ...additional FormPage fiels and content_panels
def get_form_fields(self):
# get form_fields as defined by the super class & convert to list
# otherwise returns queryset
fields = list(super(FormPage, self).get_form_fields())
# append instances of FormField - not actually stored in the db
# field_type can only be one of the following:
# 'singleline', 'multiline', 'email', 'number', 'url', 'checkbox',
# 'checkboxes', 'dropdown', 'multiselect', 'radio', 'date',
# 'datetime', 'hidden'
# Important: Label MUST be unique in each form
# `insert(0` will prepend these items, so here ID will be first
fields.insert(0, FormField(
label='Employee Name',
field_type='singleline',
required=False,
help_text="Employee's Name"))
fields.insert(0, FormField(
label='Employee Email',
field_type='email',
required=False,
help_text="Employee's Email"))
fields.insert(0, FormField(
label='Employee ID',
field_type='number',
required=False,
help_text="Employee's ID"))
return fields
Note: When creating our FormField instances, these are not stored in the database, but their responses will be. You should provide the attributes label, field_type, required and help_text.
2 - Ensure there are no label conflicts on existing Forms
If the form label 'Employee ID' is used already in a form - not sure what will happen but it will likely break things so check you do not have conflicts in existing form pages.
Note: If the label is the same, you will not loose your data from previous submissions. All data is stored for past submissions even if you change the FormFields in use.
3 - Override the label field on FormField with some validation
In myapp/models.py wherever you have defined your FormField model, add the following:
from django.core.exceptions import ValidationError
# ... other imports and then models
RESERVED_LABELS = ['Employee Name', 'Employee Email', 'Employee ID']
def validate_label(value):
if value in RESERVED_LABELS:
raise ValidationError("'%s' is reserved." % value)
class FormField(AbstractFormField):
# page = ...
# redefine 'label' field so we can ensure there will be no conflicts with constant fields
label = models.CharField(
verbose_name='label',
max_length=255,
help_text='The label of the form field, cannot be one of the following: %s.'
% ', '.join(RESERVED_LABELS),
validators=[validate_label]
)
RESERVED_VALUES should match the labels used in your FormPage model.
This creates a simple Django Field Validator to check that you will not have conflicting labels. It also adds some nice help text so users do not get confused.
4 - Migrate
You should also do a migrations as you have now changed the label field on the FormField model.

Yii2 REST API fields (user?fields=id) does not work

I've got the REST API working with the user table provided in the base migration. I can "GET /users" just fine, but according to the docs, I should also be able to "GET /users?fields=id" and receive a response limited to the id fields.
But instead I get the full result set.
Under the topic Fields in Yii2 Guide it says;
// only returns field id and email, provided they are declared in fields()
http://localhost/users?fields=id,email
so you have to override the fields() function to get the expected result.
// explicitly list every field, best used when you want to make sure the changes
// in your DB table or model attributes do not cause your field changes (to keep API backward compatibility).
public function fields()
{
return [
// field name is the same as the attribute name
'id',
// field name is "email", the corresponding attribute name is "email_address"
'email' => 'email_address',
// field name is "name", its value is defined by a PHP callback
'name' => function ($model) {
return $model->first_name . ' ' . $model->last_name;
},
];
}

Symfony2 entityaudit: Add field on revision table

I have 2 entities in my bundle that are audited via simplethings/entity-audit.
I would like to add a field to REVISIONS table call "reason". Every time a user updates or delete an entity, he/she needs to especicify an reason for doing that (why updating/deleting) via form, and this reason should be associated to the entity revision.
How would you guys do it? I dont have much experience in OOP.
Thank you very much in advance.
for adding field you need to add field in your database like 'ip' next you change your bundle in file "logRevisionsListener.php"
private function getRevisionId()
{
if ($this->revisionId === null) {
$this->conn->insert($this->config->getRevisionTableName(), array(
'timestamp' => date_create('now'),
'username' => $this->config->getCurrentUsername(),
'ip' => $this->config->getCurrentUsername(),(not correct just for test it give me the user name)
), array(
Type::DATETIME,
Type::STRING,
Type::STRING
));
.
.
}
I added here the ip field and change your Revision.php file by adding your field with the getter method