This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Following this steps (https://vimeo.com/108040919) I could extend the plugin with PayPal login method.
The problem is when I delete a user, the new table with extra users fields are not removed.
I suppose that I need is adding a event beforeDelete
for the user model. But I don't figure out how can I do that from the User::extend
method.
This is the boot
method of my component
public function boot() {
UserModel::extend(function(UserModel $model){
$model->hasOne['paypal'] = ['\PlanetaDelEste\Mag\Models\Paypal'];
});
UserController::extendFormFields(function($form, $model, $context){
if(!$model instanceof UserModel)
return;
if(!$model->exists)
return;
PaypalModel::getFromUser($model);
$form->addTabFields([
'paypal[family_name]' => [
'label' => 'planetadeleste.mag::lang.paypal.family_name_label',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'left',
'attributes' => ['readonly' => 'true']
],
'paypal[name]' => [
'label' => 'planetadeleste.mag::lang.paypal.name_label',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'right',
'attributes' => ['readonly' => 'true']
],
'paypal[account_type]' => [
'label' => 'planetadeleste.mag::lang.paypal.account_type_label',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'left',
'attributes' => ['readonly' => 'true']
],
'paypal[given_name]' => [
'label' => 'planetadeleste.mag::lang.paypal.given_name_label',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'right',
'attributes' => ['readonly' => 'true']
],
'paypal[hash]' => [
'label' => 'planetadeleste.mag::lang.paypal.hash_label',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'left',
'attributes' => ['readonly' => 'true']
],
'paypal[locale]' => [
'label' => 'planetadeleste.mag::lang.paypal.locale_label',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'right',
'attributes' => ['readonly' => 'true']
],
'paypal[zone]' => [
'label' => 'planetadeleste.mag::lang.paypal.zone_label',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'left',
'attributes' => ['readonly' => 'true']
],
'paypal[phone]' => [
'label' => 'planetadeleste.mag::lang.paypal.phone_label',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'right',
'attributes' => ['readonly' => 'true']
],
'paypal[email]' => [
'label' => 'planetadeleste.mag::lang.paypal.email_label',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'left',
'attributes' => ['readonly' => 'true']
],
'paypal[age_range]' => [
'label' => 'planetadeleste.mag::lang.paypal.age_range_label',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'right',
'attributes' => ['readonly' => 'true']
],
'paypal[birthday]' => [
'label' => 'planetadeleste.mag::lang.paypal.birthday_label',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'left',
'attributes' => ['readonly' => 'true']
],
'paypal[payer_id]' => [
'label' => 'planetadeleste.mag::lang.paypal.payer_id',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'right',
'attributes' => ['readonly' => 'true']
],
'paypal[language]' => [
'label' => 'planetadeleste.mag::lang.paypal.language',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'left',
'attributes' => ['readonly' => 'true']
],
'paypal[picture]' => [
'label' => 'planetadeleste.mag::lang.paypal.picture',
'tab' => 'PayPal',
'type' => 'text',
'span' => 'right',
'attributes' => ['readonly' => 'true']
],
]);
});
}
The PayPal Model
public $belongsTo = [
'user' => ['\RainLab\User\Models\User']
];
Thanks.
Last updated
You could use a model event for this, try adding this to your boot()
method.
UserModel::deleted(function($user) {
$user->paypal->delete();
});
Last updated
Thanks @Scott changing delete to deleting work fine.
UserModel::deleting(function($user) {
$user->paypal->delete();
});
or
User::extend( function($model) { $model->bindEvent('model.beforeDelete', function() use ($model) { $model->paypal && $model->paypal->delete(); }); });
1-5 of 5