Announcement

Collapse
No announcement yet.

Access the settings of the field in the Admin panel

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Access the settings of the field in the Admin panel

    Hi,
    I'm using a hook for phone control. But I want to check this control by looking at the checkbox in the phoneNumber field in the entity.
    Is it possible to access the field settings within the Hook parameters?

    for example;
    Code:
    Entity $entity, array $options = array()
    [I]$options->phoneNumber->checkbox == true ? like this[/I]
    I hope you understand me.
    Attached Files

  • #2
    like this JS
    Think of it as php --> this.model.getFieldParam(this.name, 'max');

    Comment


    • #3
      Hi,
      $this->getMetadata()->get(['entityDefs', $entityType, 'fields', $fieldName, $parameterName])

      Comment


      • #4
        Originally posted by tanya View Post
        Hi,
        $this->getMetadata()->get(['entityDefs', $entityType, 'fields', $fieldName, $parameterName])
        Thank you for your answer. If you have time, I have one more question.
        The $entityType variable does not exist in my parameters. I've defined a global hook. Can I access the Scope name from the $entity variable?

        Comment


        • #5
          $this->getMetadata()->get('scopes');

          but don't forget to check if it is entity and not disabled
          open data/cache/application/metadata.php

          Comment


          • #6
            I completed it like this. Is it correct ?
            Code:
            $entityType = $this->getMetadata()->get('scopes');
            Because I will use it like this.
            if($entityType == "Lead" || $entityType == "Account")

            Comment


            • #7
              No, it will return the list of all scopes.
              If you need only these to, you can use a variable

              $this->getMetadata()->get(['entityDefs', $entityType, 'fields', $fieldName, $parameterName])

              $this->getMetadata()->get(['entityDefs', 'Lead', 'fields', 'phoneNumber', 'required'])

              Comment


              • #8
                Yes I know that. But if I use certain entity, I want to check. So I will check my entity. I hope I can tell.

                Is this the right way? example;

                Code:
                <?php
                
                namespace Espo\Custom\Hooks\Common;
                
                use Espo\ORM\Entity;
                use \Espo\Core\Exceptions\Error;
                
                class PhoneControl extends \Espo\Core\Hooks\Base
                {    
                    public function beforeSave(Entity $entity, array $options = array())
                    {
                        $entityType = $entity->getEntityType();
                        $fieldName = $entity->get('phoneNumber');
                
                        $requiredCheck = $this->getMetadata()->get(['entityDefs', $entityType, 'fields', $fieldName, 'required']);
                
                        if($entityType == "Lead" || $entityType == "Account" || $entityType == "User" || $entityType == "Contact") {
                            if($entity->get('phoneNumber')) {
                                if($requiredCheck === true) {
                                    $this->checkPhoneNumber($entity->get('phoneNumber'));
                                }
                            }
                        }
                    }
                }

                Comment


                • #9

                  $fieldName = 'phoneNumber';
                  $requiredCheck= ... after if and... reading your code... if phoneNumber is not empty (is set) and field is required, then call checkPhoneNumber method? if the field is required, phoneNumber can't be empty, if the field is on the form

                  Comment


                  • dangerdodis
                    dangerdodis commented
                    Editing a comment
                    It's work
                Working...
                X